JS get the current time: Use JS to get the current time

Source: Internet
Author: User
Tags current time getdate idate integer string


Most of the time may use JS to get the current time, and then based on the year, month, day to regroup into the string you want, now I want to get the current time in the form of the 2011-05-06,
JS getFullYear () can return, getmonth () only returns the integer from 0-11, GetDate () returns the integer from 1-31, that how to get to 05 and 06 of such strings in a relatively simple way, In substr and substring are all read from the beginning to the end, detailed view of the JS manual, found that the String.slice function, he can start from the tail count, and finally use the following method, fix!
var dt = new Date ();
var iyear = Dt.getfullyear ();
var imonth = ("0" + (dt.getmonth () + 1)). Slice (-2);
var idate = ("0" + dt.getdate ()). Slice (-2);
document.write (iyear + "-" + Imonth + "-" + idate);
This article links http://www.cxybl.com/html/wyzz/JavaScript_Ajax/20121026/33268.html

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.