简体   繁体   中英

Wrong date format on iOS in Ionic5 hybrid app (Appery.io platform)

I did not try that but I got it working now in xcode simulator. This function below works fine in Android but not in iPhone (Tracking-page):

const MyDate = new Date(timestamp + " UTC"); this.itemTimestamp = MyDate.toLocaleString();

In iPhone it gives INVALID DATE error.

I see the specification here: https://www.elliotjreed.com/blog/2019-03-20/invalid-date-format-in-javascript-on-ios-devices

But Appery says: "The Date type value is a string which contains a UTC timestamp stored in ISO 8601 format with millisecond precision: YYYY-MM-DDThh:mm:ss.mmm."( https://docs.appery.io/reference/database-api-data-types#date ) I don't know if this is the issue in the platform or in the code of mine.. So what is the correct format for that platform with or w/o "Z" at the end?

iOS supports the ISO format only, like '2022-02-10T21:26:11.119Z'

Z is the time zone offset specified as “Z” (for UTC) or either

More details you can find here: https://262.ecma-international.org/5.1/#sec-15.9.1.15

So in the case, if you don't set the timezone the UTC will be selected automatically ("Z")

It is better to set the timezone every time to avoid issues with the wrong timezone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM