微信小程序实例:实现系统时间、时间戳时间以及时间戳加减的获取代码

网友投稿 1079 2022-10-05

微信小程序实例:实现系统时间、时间戳时间以及时间戳加减的获取代码

微信小程序实例:实现系统时间、时间戳时间以及时间戳加减的获取代码

本篇文章给大家带来的内容是关于微信小程序实例:实现系统时间、时间戳时间以及时间戳加减的获取代码 ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

//获取当前时间戳 var timestamp = Date.parse(new Date()); timestamp = timestamp / 1000; console.log("当前时间戳为:" + timestamp); //获取当前时间 var n = timestamp * 1000; var date = new Date(n); //年 var Y = date.getFullYear(); //月 var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1); //日 var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); //时 var h = date.getHours(); //分 var m = date.getMinutes(); //秒 var s = date.getSeconds(); console.log("当前时间:" +Y+M+D+h+":"+m+":"+s); //转换为时间格式字符串 console.log(date.toDateString()); console.log(date.toGMTString()); console.log(date.toISOString()); console.log(date.toJSON()); console.log(date.toLocaleDateString()); console.log(date.toLocaleString()); console.log(date.toLocaleTimeString()); console.log(date.toString()); console.log(date.toTimeString()); console.log(date.toUTCString());-

//时间、时间戳加减 以加一天举例,聪明的你肯定触类旁通 //加一天的时间戳: var tomorrow_timetamp = timestamp + 24 * 60 * 60; //加一天的时间: var n_to = tomorrow_timetamp * 1000; var tomorrow_date = new Date(n_to); //加一天后的年份 var Y_tomorrow = tomorrow_date.getFullYear(); //加一天后的月份 var M_tomorrow = (tomorrow_date.getMonth() + 1 < 10 ? '0' + (tomorrow_date.getMonth() + 1) : tomorrow_date.getMonth() + 1); //加一天后的日期 var D_tomorrow = tomorrow_date.getDate() < 10 ? '0' + tomorrow_date.getDate() : tomorrow_date.getDate(); //加一天后的时刻 var h_tomorrow = tomorrow_date.getHours(); //加一天后的分钟 var m_tomorrow = tomorrow_date.getMinutes(); //加一天后的秒数 var s_tomorrow = tomorrow_date.getSeconds();-

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:通信电平转换指南
下一篇:【无标题】物联网安全挑战:为什么企业现在必须评估它们
相关文章

 发表评论

暂时没有评论,来抢沙发吧~