Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js] 第688天 以下时间处理在IOS上会遇到什么问题?如何解决? #3641

Open
haizhilin2013 opened this issue Mar 3, 2021 · 3 comments
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

第688天 以下时间处理在IOS上会遇到什么问题?如何解决?

3+1官网

我也要出题

var time = "2021-02-19 05:02:28";
time = new Date(time).getTime();
console.log(time);

@haizhilin2013 haizhilin2013 added the js JavaScript label Mar 3, 2021
@wheatup
Copy link

wheatup commented Mar 4, 2021

iOS和mac使用的JSC引擎的时间格式只支持ISO时间格式,日期与时间之间用T分隔:

var time = "2021-02-19 05:02:28";
time = time.replace(/\s/, 'T');
time = new Date(time).getTime();
console.log(time);

@WayneGongCN
Copy link

iOS和mac使用的JSC引擎的时间格式只支持ISO时间格式,日期与时间之间用T分隔:

var time = "2021-02-19 05:02:28";
time = time.replace(/\s/, 'T');
time = new Date(time).getTime();
console.log(time);

在维基百科中,国际标准ISO 8601 时间格式相关解释如下:

年由4位数字组成YYYY,或者带正负号的四或五位数字表示±YYYYY。以公历公元1年为0001年,以公元前1年为0000年,公元前2年为-0001年,其他以此类推。应用其他纪年法要换算成公历,但如果发送和接受信息的双方有共同一致同意的其他纪年法,可以自行应用。
月、日用两位数字表示:MM、DD。
只使用数字为基本格式。使用短横线"-"间隔开年、月、日为扩展格式。

在 macOS 下 Safari 中,将时间字符串中日期分隔符 - 改成 / 斜杠分割也能识别:

console.log(new Date('2021/02/19 05:02:28’))
// Fri Feb 19 2021 05:02:28 GMT+0800 (CST)

@JvanBran
Copy link

JvanBran commented Mar 4, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js JavaScript
Projects
None yet
Development

No branches or pull requests

4 participants