The FormatDate function is output in the time format in javascript. The time format is formatdate.

Source: Internet
Author: User

The FormatDate function is output in the time format in javascript. The time format is formatdate.

This example describes how to output the FormatDate function in time format in javascript. Share it with you for your reference. The details are as follows:

Javascript does not provide a function for inputting datetime content formats like fmt labels:
The following is my time output function, which is directly placed in the tag for calling. The Code is as follows:
Copy codeThe Code is as follows: Date. prototype. Format = function (fmt) {// author: meizz
If (this = "Invalid Date "){
Return "";
}
Var o = {
"M +": this. getMonth () + 1, // month
"D +": this. getDate (), // day
"H +": this. getHours (), // hour
"M +": this. getMinutes (), // minute
"S +": this. getSeconds (), // second
"Q +": Math. floor (this. getMonth () + 3)/3), // quarter
"S": this. getMilliseconds ()
// Millisecond
};
If (/(y +)/. test (fmt ))
Fmt = fmt. replace (RegExp. $1, (this. getFullYear () + "")
. Substr (4-RegExp. $1. length ));
For (var k in o)
If (new RegExp ("(" + k + ")"). test (fmt ))
Fmt = fmt. replace (RegExp. $1, (RegExp. $1. length = 1 )? (O [k])
: ("00" + o [k]). substr ("" + o [k]). length )));
Return fmt;
}

Used directly
Copy codeThe Code is as follows: new Date (time variable). Format ("yyyy-MM-dd HH: mm: ss ")

I hope this article will help you design javascript programs.

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.