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

Format error in iOS 11.3 #73

Closed
DiamondYuan opened this issue Apr 27, 2018 · 14 comments
Closed

Format error in iOS 11.3 #73

DiamondYuan opened this issue Apr 27, 2018 · 14 comments
Labels
☢️Bug Something isn't working discussion Further discussion

Comments

@DiamondYuan
Copy link

In PC dayjs('2018-09-06T17:00:00.000+0000') return Thu, 06 Sep 2018 17:00:00 GMT
In Iphone dayjs('2018-09-06T17:00:00.000+0000') return Invalid Date

@iamkun iamkun added ☢️Bug Something isn't working discussion Further discussion labels Apr 27, 2018
@iamkun
Copy link
Owner

iamkun commented Apr 28, 2018

Seems, '2018-09-06T17:00:00.000+0000' is not a standard date format? (need reference here)

If so, should we support it?

@sriksm19
Copy link

sriksm19 commented Apr 28, 2018

@iamkun
Copy link
Owner

iamkun commented Apr 28, 2018

May be the best way to deal with these non-standard date format is to format it before send it to dayjs ?

const dateString = '2018-09-06T17:00:00.000+0000'.replace(/-/g,'/').replace('T', ' ')
dayjs(dateString)

@Frondor Frondor mentioned this issue Apr 30, 2018
@DiamondYuan
Copy link
Author

@iamkun
https://segmentfault.com/q/1010000006941577

2016-09-18T08:01:01.000+0000 这种格式应该是 RFC 3339 中定义的。关于时区的部分,参考 RFC 2822。

从 RFC 2822 中可以看到 +0000 是合法的,不知道为啥 Safari 不支持。

moment('2016-09-18T08:01:01.000+0000').format('YYYY/MM/DD') support.

我用了下面的方法成功了
const s = "2016-09-19T09:05:07.870+0000";
s.replace(/(+\d{2})(\d{2})$/, "$1:$2");

@xx45
Copy link
Contributor

xx45 commented May 7, 2018

Thanks, seems a nice solution. Maybe we could add this to our core ?@iamkun

Besides, nobody should use something else than ISO8601😃

@Przeblysk
Copy link

var startTime = "2018-05-18T16:00:00.000+0000";
startTime = startTime.replace(/(+\d{2})(\d{2})$/, "$1:$2");

it's work

@shenghanqin
Copy link

let time = '2019-01-01T12:21:10+0800'

console.log(dayjs(time)) // Chrome OK, Firefox OK, Safari NaN
console.log(dayjs(time.replace(/-/g, '/').replace(/T/g, ' '))) // Chrome OK, Firefox NaN, Safari OK

So, I write a Function to solve this problem.

export let dateFormat = (date) => {
  let ua = navigator.userAgent.toLowerCase()

  return /firefox/i.test(ua) // For Firefox browser
    ? date
    : date.replace(/-/g, '/').replace(/T/g, ' ')
}

@shenghanqin
Copy link

shenghanqin commented Feb 17, 2019

I think, it is not resloved in 1.8.3 dayjs not work in safari

@ghost
Copy link

ghost commented Feb 17, 2019

@shenghanqin I use

import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
dayjs.extend(customParseFormat)
dayjs('2018-09-06T17:00:00.000+0000', 'YYYY-MM-DDTHH:mm:ss.000ZZ').format()

and works well

@ghost ghost mentioned this issue Feb 26, 2019
@wangxiaocuo
Copy link

@shenghanqin I use

import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
dayjs.extend(customParseFormat)
dayjs('2018-09-06T17:00:00.000+0000', 'YYYY-MM-DDTHH:mm:ss.000ZZ').format()

and works well

oh, thank you! It works well

@froyo-naux
Copy link

dayjs@1.8.24 , has some problem

@iamkun
Copy link
Owner

iamkun commented Apr 17, 2020

@NauxChen For consistent results parsing anything other than ISO 8601 strings, you should use String + Format. https://day.js.org/docs/en/parse/string-format

demo: #73 (comment)

@harmonikas996
Copy link

harmonikas996 commented Sep 20, 2023

I had Invalid Date issue with Safari when I wanted to mark datetime string as UTC by adding z at the end of the string.

I managed to fix the issue by concatenating Z (not z) at the end of my datetime string I got from an API. Now it works great on both Safari and Chrome.

My API datetime format after this fix: YYYY-MM-DD HH:mm:ssZ

@bzdybel
Copy link

bzdybel commented Mar 21, 2024

I had Invalid Date issue with Safari when I wanted to mark datetime string as UTC by adding z at the end of the string.

I managed to fix the issue by concatenating Z (not z) at the end of my datetime string I got from an API. Now it works great on both Safari and Chrome.

My API datetime format after this fix: YYYY-MM-DD HH:mm:ssZ

Exactly same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☢️Bug Something isn't working discussion Further discussion
Projects
None yet
Development

No branches or pull requests

10 participants