没有合适的资源?快使用搜索试试~ 我知道了~
首页微信小程序获取系统时间、时间戳、时间时间戳加减
微信小程序获取系统时间、时间戳、时间时间戳加减
需积分: 10 9 下载量 90 浏览量
更新于2023-03-03
评论
收藏 32KB PDF 举报
[javascript] view plain copy //获取当前时间戳 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(); //月
资源详情
资源评论
资源推荐
微信小程序获取系统时间、时间戳、时间时间戳加减微信小程序获取系统时间、时间戳、时间时间戳加减
[javascript] view plain copy
1. //获取当前时间戳
2. var timestamp = Date.parse(new Date());
3. timestamp = timestamp / 1000;
4. console.log("当前时间戳为:" + timestamp);
5.
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("当前时间:" +Y+M+D+h+":"+m+":"+s);
23.
24. //转换为时间格式字符串
25. console.log(date.toDateString());
26.
27. console.log(date.toGMTString());
28.
29. console.log(date.toISOString());
30.
31. console.log(date.toJSON());
32.
33. console.log(date.toLocaleDateString());
34.
35. console.log(date.toLocaleString());
36.
37. console.log(date.toLocaleTimeString());
38.
39. console.log(date.toString());
40.
41. console.log(date.toTimeString());
42.
43. console.log(date.toUTCString());
[javascript] view plain copy
1. //时间、时间戳加减 以加一天举例,聪明的你肯定触类旁通
2. //加一天的时间戳:
3. var tomorrow_timetamp = timestamp + 24 * 60 * 60;
4. //加一天的时间:
5. var n_to = tomorrow_timetamp * 1000;
6. var tomorrow_date = new Date(n_to);
7. //加一天后的年份
8. var Y_tomorrow = tomorrow_date.getFullYear();
9. //加一天后的月份
10. var M_tomorrow = (tomorrow_date.getMonth() + 1 < 10 ? '0' + (tomorrow_date.getMonth() + 1) : tomorrow_date.getMonth() + 1);
11. //加一天后的日期
12. var D_tomorrow = tomorrow_date.getDate() < 10 ? '0' + tomorrow_date.getDate() : tomorrow_date.getDate();
13. //加一天后的时刻
14. var h_tomorrow = tomorrow_date.getHours();
15. //加一天后的分钟
16. var m_tomorrow = tomorrow_date.getMinutes();
17. //加一天后的秒数
18. var s_tomorrow = tomorrow_date.getSeconds();
weixin_38630853
- 粉丝: 4
- 资源: 952
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
- MW全能培训汽轮机调节保安系统PPT教学课件.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0