微信小程序获取当前时间戳

太过爱你忘了你带给我的痛 2021-09-30 09:52 623阅读 0赞

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMjQxNTA0_size_16_color_FFFFFF_t_70

  1. onLoad: function(options) {
  2. //获取当前时间戳
  3. var timestamp = Date.parse(new Date());
  4. timestamp = timestamp / 1000;
  5. console.log("当前时间戳为:" + timestamp);
  6. //获取当前时间
  7. var n = timestamp * 1000;
  8. var date = new Date(n);
  9. //年
  10. var Y = date.getFullYear();
  11. //月
  12. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  13. //日
  14. var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  15. //时
  16. var h = date.getHours();
  17. //分
  18. var m = date.getMinutes();
  19. //秒
  20. var s = date.getSeconds();
  21. //转换为时间格式字符串
  22. console.log(date.toDateString());
  23. console.log(date.toGMTString());
  24. console.log(date.toISOString());
  25. console.log(date.toJSON());
  26. console.log(date.toLocaleDateString());
  27. console.log(date.toLocaleString());
  28. console.log(date.toLocaleTimeString());
  29. console.log(date.toString());
  30. console.log(date.toTimeString());
  31. console.log(date.toUTCString());
  32. console.log("当前时间:" + Y + M + D + h + ":" + m + ":" + s);
  33. },

发表评论

表情:
评论列表 (有 0 条评论,623人围观)

还没有评论,来说两句吧...

相关阅读