"JavaScript" JS converts Java timestamp to date type

Source: Internet
Author: User
Tags timestamp to date

Encounter a small demand, because to fill the date plug-in data, the foreground to the Java background from the date type of data into the YYYY-MM-DD format of time data. With JSON transmission, Java's date type data is automatically converted to a timestamp, such as "1470672000000".

JS Processing code:

function FormatDate (date) {dates= Date.split ("/"); if(Dates.length = =3) {        if(dates[1].length = =1) {dates[1] ="0"+ dates[1]; }        if(dates[2].length = =1) {dates[2] ="0"+ dates[2]; } Date= Dates.join ("-"); returndate; } Else {        return NULL; }}function Parsetime (timestamp) {varDate =NewDate (parseint (timestamp)). toLocaleDateString ();
The output is 2016/8/9 date=formatdate (date);
The output is 2016-08-09 and meets the YYYY-MM-DD format requirementsreturndate;}

"1470672000000" after the Parsetime function processing result is "2016-08-09".

"JavaScript" JS converts Java timestamp to date type

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.