欢迎来到258分享网,纯净的网络源码分享基地!

258资源分享网

全部作品
全部作品
网站源码
微信源码
素材特效
源码插件
视频教程
建站学院
热门搜索: 织梦  农业种植  农业  安全设置  官方
258资源分享 > 建站学院 > 微信开发 > 微信小程序获取系统时间、时间戳、时间时间戳加减

推荐下载

HTML5响应式自适应网咯设计

2020-05-12   浏览:736

高端HTML5响应式企业通用网

2020-05-06   浏览:517

html5响应式外贸网站英文版

2020-05-08   浏览:505

HTML5自适应律师工作室类网

2020-04-04   浏览:501

HTML5影视传媒文化公司类网

2020-05-12   浏览:495

微信小程序获取系统时间、时间戳、时间时间戳加减

发布时间:2020-11-20  

    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());  

[javascript] view plain copy

 

//时间、时间戳加减 以加一天举例,聪明的你肯定触类旁通  

    //加一天的时间戳:  

    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();  

本文标签

:备案管家服务帮您把复杂流程变简单,解决您在进行网站备案过程中遇到的效率低下和成功率不高的问题。个人300/2个域名,企业500/5个域名,qq1650004.