JavaScript date format processing

Source: Internet
Author: User

I. The date and time returned by the server has a T

The date type data for the action return foreground in ASP. NET MVC is a T, such as: 2015-07-07t10:15:01.

Such data will be automatically added to the Chrome browser for 8 hours, as follows:

And in IE, there is no problem,

Workaround: You can handle JSON serialization: you need to use the Newtonsoft.json serialization output,

            New jsonserializersettings ();             = Dateformathandling.isodateformat;             " YYYY-MM-DD HH:mm:ss " ;             New Func<jsonserializersettings> (() =            {                return  setting;            });

Two. JavaScript handling of dates and times with T

My plan is to replace T.

    function (datestring) {        if (!  datestring) {            return "";        }         return New Date (Datestring.replace (/t| z/g, ");    },

Three. Differences in date processing between IE and Chrome browser

The main difference is that IE does not recognize the date type, such as: 2015-07-07 10:15:01, if it is only a date, is possible,

And Chrome is all you can

The solution is to replace the date '-' with a '/'

    function (datestring) {        if (!  datestring) {            return "";        }         return New Date (Datestring.replace (/-/g, '/'). Replace (/t| z/g, ");    },

Four. Under the Spit slot ie

IE8, this also error, and the high version of IE is no problem

The time to add T, and the time without T is not the same

JavaScript date format processing

Related Article

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.