Java and JS time format __ Large data

Source: Internet
Author: User

Today ate the time format of the big loss, but also do not understand the time format of JS, pit for a long time. Remember, a long memory to share with you.

Java date formatting: Remember that the format is Yyyy-mm-dd HH:MM:SS, which is case-sensitive.

public static void Main (string[] args) {
    //correct time format
    String ddate = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (new Date ());
    Error time format
    String ddate1 = new SimpleDateFormat ("Yyyy-mm-dd HH:MM:ss"). Format (new Date ());

    System.out.println (ddate);
    2015-12-30 14:02:56
    System.out.println (ddate1);
    2015-02-30 14:12:56
}

JS Date format: Remember that the JS format is YYYY-MM-DD hh:mm:ss, are lowercase. Strictly case sensitive.

(new Date ()). Format ("Yyyy-mm-dd")
"2015-12-30"
(new Date ()). Format ("Yyyy-mm-dd")
"2015-51-30"
(new Date (1451444616000)). Format ("Yyyy-mm-dd hh:mm:ss")
"2015-12-30 11:12:36"
( 1451444616000). Format ("Yyyy-mm-dd hh:MM:ss")
"2015-03-30 11:03:36"

Error occurs because:
Because the data used is the datetime type, from the background to get data to the foreground, the display date format to 1451444616000, after YYYY-MM-DD HH:mm:ss format, found that the time is not right, Instead of the date data displayed through the Navicat query 2015-12-30 11:12:36. Because of the JS time format used in the same way as Java, showing the wrong time, leading to the search no problem. Finally a careful examination, only to understand the format is not uniform.

Finally, note:

Java Time formatting:

New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (new Date ())

JS Time Format:

(New Date ()). Format ("Yyyy-mm-dd hh:mm:ss")
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.