Coder Social home page Coder Social logo

Format error in iOS 11.3 about dayjs HOT 14 CLOSED

iamkun avatar iamkun commented on May 6, 2024
Format error in iOS 11.3

from dayjs.

Comments (14)

 avatar commented on May 6, 2024 10

@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.

Przeblysk avatar Przeblysk commented on May 6, 2024 7

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

it's work

from dayjs.

DiamondYuan avatar DiamondYuan commented on May 6, 2024 1

@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.

harmonikas996 avatar harmonikas996 commented on May 6, 2024 1

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.

iamkun avatar iamkun commented on May 6, 2024

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.

sriksm19 avatar sriksm19 commented on May 6, 2024

could be probably due to https://stackoverflow.com/questions/6427204/date-parsing-in-javascript-is-different-between-safari-and-chrome

from dayjs.

iamkun avatar iamkun commented on May 6, 2024

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.

xx45 avatar xx45 commented on May 6, 2024

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

Besides, nobody should use something else than ISO8601😃

from dayjs.

shenghanqin avatar shenghanqin commented on May 6, 2024
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.

shenghanqin avatar shenghanqin commented on May 6, 2024

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

from dayjs.

wangxiaocuo avatar wangxiaocuo commented on May 6, 2024

@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.

froyo-naux avatar froyo-naux commented on May 6, 2024

[email protected] , has some problem

from dayjs.

iamkun avatar iamkun commented on May 6, 2024

@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.

bzdybel avatar bzdybel commented on May 6, 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

from dayjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.