Problem with time resolved in Vue showing Nan on iOS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.