Small program development pit -------- IOS time is displayed as NaN

The reason is that ios does not support the date in the format of 2018-04-26 passed in the database, and it must be converted to the format of 2018/04/26 to display properly;

Example: endtimes is the date returned

Small program implementation example:

var endtime = obj.data.endtime
var endtimes = endtime.replace(/\-/g, "/")
new Date(endtimes).getTime() //Get seconds, you can switch to .getDate() to get days or .getMonth() + 1 to get months and other Date operations. . .

Implementation steps:

Step 1: The request interface returns the date, usually in the format of 2018-04-26 09:41:55. If you use this date directly, call new Date(endtimes).getTime() to get the seconds or the year and month day, IOS will display NaN

At this point, the second step is required, the second step: use the replace function, call endtime.replace(/\-/g, "/") to replace all "-" with "/", and convert the date to 2018/04/26 09:41:55 This format, at this time, both ios and Android recognize the date in this format

Step 3: Finally, call new Date(endtimes).getTime() to get the seconds or the year, month, and day to display success.

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324883506&siteId=291194637