Comments (14)
@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
from dayjs.
var startTime = "2018-05-18T16:00:00.000+0000";
startTime = startTime.replace(/(+\d{2})(\d{2})$/, "$1:$2");
it's work
from dayjs.
@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");
from dayjs.
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
from dayjs.
Seems, '2018-09-06T17:00:00.000+0000' is not a standard date format? (need reference here)
If so, should we support it?
from dayjs.
could be probably due to https://stackoverflow.com/questions/6427204/date-parsing-in-javascript-is-different-between-safari-and-chrome
from dayjs.
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)
from dayjs.
Thanks, seems a nice solution. Maybe we could add this to our core ?@iamkun
Besides, nobody should use something else than ISO8601😃
from dayjs.
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, ' ')
}
from dayjs.
I think, it is not resloved in 1.8.3 dayjs not work in safari
from dayjs.
@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
from dayjs.
[email protected] , has some problem
from dayjs.
@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)
from dayjs.
I had
Invalid Date
issue with Safari when I wanted to mark datetime string as UTC by addingz
at the end of the string.I managed to fix the issue by concatenating
Z
(notz
) 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
from dayjs.
Related Issues (20)
- Inconsistent behaviour of diff(.., 'months) on leap days
- .diff method returns the wrong result
- add() result is wrong with timezone
- Best way to get "This Weekend" or "Next Weekend" ?
- Converting timestamp to utc returns same timestamp
- timezone output wrong result HOT 1
- fix localized format for `el` locale
- 关于闰年的 2月29日 年份加减问题?应当是多少? HOT 2
- Error in parsing array format date
- Adding a 1000 ms duration doesn't change the timestamp
- dayjs Not Working Properly in US Region when I use it with vue-hotel-datepicker.
- isValid bug
- dayjs(value, formats, true).isValid() bug
- DayJS Timezone Bug with Daylight Savings
- Converting longform Lithuanian date does not work for December
- Incorrect handling of wrong input in timzone plugin HOT 1
- Strict flag not working with `customParseFormat`
- 02-29.set("year", 2024) return 03-01
- Dates less than 1883-11-19 are given a time?
- year format should use yyyy instead of YYYY
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dayjs.