Use JavaScript to format the date type read from the database to the desired type. _ Time and date

Source: Internet
Author: User
During page initialization, JavaScript is used to format the date type read from the database to the desired type. Format it as yyyy MM mm dd hh mm mm ss seconds. You can refer to the following code for free use. The Code is as follows:


// Input the date data retrieved from the database
Function getformatdate (d ){
Var formate_datetime;
Var array = d. split ("");
Var date = array [0];
Var time = array [1];
Var array_date = date. split ("-");
Var array_time = time. split (":");
Var second = array_time [2]. split (".") [0];
Formate_datetime = array_date [0] + "year" + removeZero (array_date [1]) + "month" + removeZero (array_date [2]) + "day"
+ RemoveZero (array_time [0]) + "Hour" + removeZero (array_time [1]) + "Minute" + second + "second ";
Return formate_datetime;
}
// Remove the value 0 before month, day, hour, and minute
Function removeZero (data)
{
If (data. charAt (0) = "0 "){
Return data. charAt (1 );
}
Else
{
Return data;
}
}

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.