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
Seems, '2018-09-06T17:00:00.000+0000' is not a standard date format? (need reference here)
If so, should we support it?
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)
@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");
Thanks, seems a nice solution. Maybe we could add this to our core ?@iamkun
Besides, nobody should use something else than ISO8601😃
var startTime = "2018-05-18T16:00:00.000+0000";
startTime = startTime.replace(/(+\d{2})(\d{2})$/, "$1:$2");
it's work
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, ' ')
}
I think, it is not resloved in 1.8.3 dayjs not work in safari
@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
@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
[email protected] , has some problem
@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: https://github.com/iamkun/dayjs/issues/73#issuecomment-464443622
Most helpful comment
var startTime = "2018-05-18T16:00:00.000+0000";
startTime = startTime.replace(/(+\d{2})(\d{2})$/, "$1:$2");
it's work