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

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 热门话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Project Zero
Project Zero
V
Vulnerabilities – Threatpost
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
C
Cisco Blogs
A
Arctic Wolf
月光博客
月光博客
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
量子位
小众软件
小众软件
Latest news
Latest news
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
N
Netflix TechBlog - Medium
K
Kaspersky official blog
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
Y
Y Combinator Blog
P
Proofpoint News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
S
Schneier on Security
D
Docker
Scott Helme
Scott Helme
MyScale Blog
MyScale Blog
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
GbyAI
GbyAI
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
H
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
J
Java Code Geeks
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tenable Blog
B
Blog
Know Your Adversary
Know Your Adversary
IT之家
IT之家

博客园 - 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