JS Time format Conversion

Source: Internet
Author: User

The new date () of the JS call is not a formatted time, for example

var date=new date ();

alert (date);

Displaying results: Wed Oct 22:28:32 utc+0800 2015

Here today to share a JS write Foramt () function, I hope to be helpful to everyone!

function Formate (datetime) {
var year = Datetime.getfullyear ();
var month = Datetime.getmonth () + 1; JS starting from 0 to take
var date = Datetime.getdate ();
var hour = datetime.gethours ();
var minutes = datetime.getminutes ();
var second = Datetime.getseconds ();

if (Month < 10) {
month = "0" + month;
}
if (Date < 10) {
Date = "0" + date;
}
if (Hour < 10) {
hour = "0" + hour;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (second < 10) {
Second = "0" + second;
}

var time = year + "-" + month + "-" + date + "+ Hour +": "+ minutes +": "+ second;
return time;
}

var date=new date ();
var datetime=format(date);
Alert (datetime);

Displayed results: 2015-10-14 22:28:32

Reference Source: http://blog.sina.com.cn/s/blog_5fe080e60100dnij.html

JS Time format Conversion

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.