2--ios date format bug in Zhou Kee

Source: Internet
Author: User
Tags live chat

In the blink of an eye again to the weekend, blink of an eye to work, blink ... Perhaps this is the meaning of a perpetual eye.

   This week continued IM (live chat), the project with Layim Mobile-modified, just "borrowed" a chat window. Because it is an embedded app page, it's natural that Android and iOS compatibility issues, this time to talk about the date format in the iOS bug.

generally we are in the page rendering time is xxxx-xx-xx, this format of the date in the iOS system is not displayed , changing the xxxx-xx-xx time format to XXXX/XX/XX will solve the problem. Use regular conversions:

/**/function formattimestamp (date,time= ' 0:0:0 '    ) {return Date.parse (new Date (' ${data} ${time} ')) | | Date.parse (new Date (' ${data.replace (/-/g, '/')} ${time} '))}formattimestamp (' 2017-11-11 ');

  JavaScript default time format we generally do not use, so we need to format, the following talk about the JavaScript time format method.

Many times, we can use the built-in method of the Date object in JavaScript to format it, such as:

varD =NewDate (); Console.log (d);//output: Mon-Nov 21:50:33 gmt+0800 (China Standard Time)Console.log (D.todatestring ());//date string, output: Mon-NovConsole.log (D.togmtstring ());//GMT, Output: Mon, Geneva 14:03:05 GMTConsole.log (D.toisostring ());//International Standards Organization (ISO) format, output: 2013-11-04t14:03:05.420zConsole.log (D.tojson ());//Output: 2013-11-04t14:03:05.420zConsole.log (D.tolocaledatestring ());//Convert to local date format, depending on the environment, output: November 4, 2013Console.log (D.tolocalestring ());//Convert to local date and time format, depending on the environment, output: November 4, 2013 PM 10:03:05Console.log (D.tolocaletimestring ());//convert to local time format, depending on the environment, output: PM 10:03:05Console.log (D.tostring ());//Convert to String, output: Mon-22:03:05 gmt+0800 (China Standard Time)Console.log (D.totimestring ());//convert to time string, output: 22:03:05 gmt+0800 (China Standard Time)Console.log (D.toutcstring ());//Convert to World time, output: Mon, Geneva 14:03:05 GMT

 If the above method does not meet our requirements, you can also customize the function to format the time, such as:

//An extension to date that converts date to a string of the specified format//the Month (m), Day (d), hour (h), Minute (m), second (s), quarter (q) can be used with 1-2 placeholders,//year (Y) can use 1-4 placeholders, milliseconds (S) with only 1 placeholders (1-3 digits)//Example://(New Date ()). Format ("Yyyy-mm-dd Hh:mm:ss. S ") ==> 2006-07-02 08:09:04.423//(New Date ()). Format ("yyyy-m-d h:m:s.s") ==> 2006-7-2 8:9:4.18Date.prototype.format =function(FMT) {//Author:meizzvaro = {"m+": This. GetMonth () + 1,//Month"D+": This. GetDate (),//Day"H +": This. GetHours (),//hours"m+": This. getminutes (),//points"S+": This. getseconds (),//seconds"q+": Math.floor (( This. GetMonth () + 3)/3),//Quarterly"S": This. Getmilliseconds ()//milliseconds};if(/(y+)/.test (FMT)) FMT = Fmt.replace (regexp.$1, ( This. getFullYear () + ""). substr (4-regexp.$1. length)); for(varKincho)if(NewRegExp ("(" + K + ")"). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length = = 1)? (O[k]): (("XX" + o[k]). substr ("" +O[k] ));returnFMT;}

Call:

// var date = timestamp or other format that can be converted by new date New

  On the first summary of time, not to be continued ...

2--ios date format bug in Zhou Kee

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.