JavaScript + Golang Processing time issues

Source: Internet
Author: User
Tags rfc
This is a creation in Article, where the information may have evolved or changed.

JavaScript + Golang Processing time issues

Today, a colleague asked JS and Golang processing time problem always have errors, so think of last year to do a project also appeared this problem, send a blog record:

Directly on the code:

javascript fragment: var  sa = $    ( ' #sa ' ). Datetimebox ( ' getValue ' ); var  ea = $ ( ' #ea ' ). Datetimebox ( ' getValue ' ); //at this time the SA and EA outputs are YYYY-MM-DD HH:mm:ss this standard format string ------------------------------------ -----var  SA1 = new  date     (SA). toisostring (); var  ea1 = new  Date     (EA). Toisostring (); //at this time SA1 and ea1 need to be ISO-8601 format: yyyy-mm-ddthh:mm:ss.sssz   
golang片段:    sa1 := form["sa"][0]    ea1 := form["ea"][0]    fmt.Println("sa1: ", sa1)    fmt.Println("ea1: ", ea1)    sa, _ := time.Parse(time.RFC3339Nano, sa1)    ea, _ := time.Parse(time.RFC3339Nano, ea1)    fmt.Println("sa: ", sa)    fmt.Println("ea: ", ea)

There is no inconsistency between the front-end time and the time saved in the database after the above processing.

Browser Console output:

Golang Program:

Golang output:

Database storage:

*

Some browsers may have incompatible issues with the ISO time, just add the following code before converting the ISO time:

    if(!Date. prototype.toisostring) {Date. prototype.toisostring = function() {         function pad(n) {          returnN <Ten?' 0 '+ N + +}return  This. getUTCFullYear () +'-'+ Pad ( This. getUTCMonth () +1) +'-'+ Pad ( This. getUTCDate ()) +' T '+ Pad ( This. getUTCHours ()) +':'+ Pad ( This. getUTCMinutes ()) +':'+ Pad ( This. getUTCSeconds ()) +'.'+ Pad ( This. getUTCMilliseconds ()) +' Z '; }    }

*

I hope you can help!

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.