本篇文章给大家带来的内容是关于微信小程序实例:实现系统时间、时间戳时间以及时间戳加减的获取代码 ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
//获取当前时间戳 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();
相关推荐:
小程序:防止点击遮罩层后遮罩层下面也反应的解决方法
微信小程序实例:分享给一个人还是分享到群的判断代码
以上就是微信小程序实例:实现系统时间、时间戳时间以及时间戳加减的获取代码的详细内容。
