介绍
这篇文章将为大家详细讲解有关小程序如何获取系统时间,时间戳时间以及时间戳加,减小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
//获取当前时间戳 ,,,var timestamp =, Date.parse (new 日期()); ,,,timestamp =, timestamp /, 1000; ,,,console.log(“当前时间戳为:“,+,时间戳); ,//获取当前时间 ,,,var n =, timestamp *, 1000; ,,,var date =, new 日期(n); ,,//年 ,,,var Y =, date.getFullYear (); ,,//月 ,,,var M =, (date.getMonth (), +, 1, & lt;, 10, ?, & # 39; 0 & # 39;, +, (date.getMonth (), +, - 1),:, date.getMonth (), +, 1); ,,//日 ,,,var D =, date.getDate (), & lt;, 10, ?, & # 39; 0 & # 39;, +, 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 日期(n_to); ,,,//加一天后的年份 ,,,var Y_tomorrow =, tomorrow_date.getFullYear (); ,,,//加一天后的月份 ,,,var M_tomorrow =, (tomorrow_date.getMonth (), +, 1, & lt;, 10, ?, & # 39; 0 & # 39;, +, (tomorrow_date.getMonth (), +, - 1),:, tomorrow_date.getMonth (), +, 1); ,,,//加一天后的日期 ,,,var D_tomorrow =, tomorrow_date.getDate (), & lt;, 10, ?, & # 39; 0 & # 39;, +, tomorrow_date.getDate (),:, tomorrow_date.getDate (); ,,,//加一天后的时刻 ,,,var h_tomorrow =, tomorrow_date.getHours (); ,,,//加一天后的分钟 ,,,var m_tomorrow =, tomorrow_date.getMinutes (); ,,,//加一天后的秒数 ,,,var s_tomorrow =, tomorrow_date.getSeconds ();
关于“小程序如何获取系统时间,时间戳时间以及时间戳加减”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看的到。