Recently, when using Vue, you encounter a countdown that appears as Nan on iOS.
Because it is a countdown payment, the idea is to get the server time and the next single time, and then turn into a second-level timestamp to do the difference.
Found on the internet says iOS is not supported for example 2018-09-01 10:00:59 This "-" connector.
The online solution is:
var data = ' 2018-09-01 12:00:00 'var time= date.parse (new Date)
Then change it with a regular match and replace it with the/
var date = ' 2018-09-01 12:00:00 'var format = date.replace (/-/g, '/')var time= Date.parse (new Date (format))
But the problem is still not resolved, and still appears as Nan on iOS
So think with Moment.js, successfully solve the problem!!!
In Vue, first introduce npm install moment--save
Import moment from ' moment/moment '
And then
// Note: The Apple phone does not support the "-" split time form, so it must be formatted to ' Yyyy/mm/dd HH:mm:ss '. the //date format is returned in the background by timestamp 2018-09-01t09:10:41.000+0000Let Transtime = Moment (date). Format (' Yyyy/mm/dd HH:mm:ss ')
Console.log (Transtime)
Output
2018/09/01 09:10:41
// convert to time stamp This . Transformtime (transtime) transformtime (t) { console.log (' time before conversion ' +t) // Use the moment tool to generate a Date object let date = Moment (t). ToDate () console.log (' Date: ' + date) // becomes a second-level timestamp return Moment (date). ValueOf () }
This omtime timestamp can be used to make a countdown to the server's time stamp for the difference.
Tested, on Android and iOS are no problem, the problem is finally settled!!!
Here mark Records and shares it with you to avoid stepping on the pit for too long.
Problem with time resolved in Vue showing Nan on iOS