惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
C
Cisco Blogs
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Scott Helme
Scott Helme
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
M
MIT News - Artificial intelligence
L
LINUX DO - 热门话题
I
InfoQ
GbyAI
GbyAI
NISL@THU
NISL@THU
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More
TaoSecurity Blog
TaoSecurity Blog
Simon Willison's Weblog
Simon Willison's Weblog
A
About on SuperTechFans
Spread Privacy
Spread Privacy
月光博客
月光博客
W
WeLiveSecurity
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
Security Latest
Security Latest
人人都是产品经理
人人都是产品经理
PCI Perspectives
PCI Perspectives
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
T
Troy Hunt's Blog
Martin Fowler
Martin Fowler
The Hacker News
The Hacker News
T
Tor Project blog
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
Stack Overflow Blog
Stack Overflow Blog
K
Kaspersky official blog
Cloudbric
Cloudbric
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
D
DataBreaches.Net
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tenable Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - Franky
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog

博客园 - KidYang

微信、支付宝个人收款码不能用于经营收款 - z 微信平台开发 微信小程序图表控件 微信小程序网络排查指引 小程序字体转换 - 转 小程序播放语音之wx.createInnerAudioContext() - 转 小程序隐藏scroll-view滚动条的实现 - 转 微信小程序scroll-view左右横向滑动 用vscode开发微信小程序,建议安装的插件 小程序涉及npm、vue的一些基础资料 visual studio 关于 Updates were rejected because the remote contains work that you do 小程序使用字体相关 大量Timer_MinBytesPerSecond,Timer_ConnectionIdle错误 - 转 微信小程序隐藏时动画效果 - 转载 System.Security.Cryptography.RSA.FromXmlString 系统找不到指定的文件和X509读取证书文件系统找不到指定的文件异常 - 转载 sqlserver 发送http请求 chrome浏览器直接打印 - z 解决webapi首次启动速度慢的问题 - z 使用第三方库(Senparc)完成小程序支付 - z
微信小程序wxs格式化日期 在 ios 端显示NaN问题及日期格式化工具
KidYang · 2020-05-10 · via 博客园 - KidYang
 1 //timestamp   时间戳
 2 //option      格式(年月日  就输入YY-MM-DD   时分  就输入 hh-mm)
 3 //
 4 function formatDate(timestamp, option) {
 5 
 6   var times = timestamp.replace("-", "/").replace("-", "/")
 7   console.log(times)
 8   var date = getDate(times);
 9   var year = date.getFullYear();
10   var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
11   var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
12   var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
13   var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
14   var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
15   var over_time = year + "/" + month + "/" + day + " " + hours + ":" + minutes + ":" + seconds
16   //***至此以上是将时间2020-03-18T01:57:23.000+0000转为正常时间格式,以下为将时间进行增加8小时解决时区差异的操作***
17   var time = getDate(Date.parse(over_time));
18   time.setTime(time.setHours(time.getHours() + 8));
19 
20   //获取 年月日
21   if (option == 'YY-MM-DD') return " " + year + "-" + month + "-" + day;
22 
23   //获取年月
24   if (option == 'YY-MM') return " " + year + "-" + month;
25 
26   //获取年
27   if (option == 'YY') return " " + year;
28 
29   //获取月
30   if (option == 'MM') return " " + month;
31 
32   //获取日
33   if (option == 'DD') return " " + day;
34 
35   //获取昨天
36   if (option == 'yesterday') return " " + day - 1;
37 
38   //获取时分秒
39   if (option == 'hh-mm-ss') return " " + hours + ":" + minutes + ":" + seconds;
40 
41   //获取时分
42   if (option == 'hh-mm') return " " + hours + ":" + minutes;
43 
44   //获取分秒
45   if (option == 'mm-ss') return minutes + ":" + seconds;
46 
47   //获取分
48   if (option == 'mm') return minutes;
49 
50   //获取秒
51   if (option == 'ss') return second;
52 
53   //默认时分秒年月日
54   return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ":" + seconds;
55 }
56 
57 
58 module.exports = {
59   formatDate: formatDate
60 }

ios端显示NaN的原因是:ios设备不支持new Date(time)的这个time格式为,即:yyyy-mm-dd。我们必须要转换成"/"格式。而wxs文件不支持new Date,所以我们需要使用getDate