JS get current time and take value operation

Source: Internet
Author: User

Take value

This.divEndDate.attr ("Value", New Date ());

var date = new Date ();

Date.getyear (); Take 2-digit years

Date.getfullyear (); Take 4-digit years

Date.getmonth (); Take the Month

Date.getdate (); Take the day

Date.gettime (); Take the current time (millisecond value)

Date.gethours (); Take the current hour

Date.getminutes (); Take the current minute

Date.getseconds (); Take the current second

Date.getmilliseconds (); Take current millisecond (0-999)

Date.tolocaletimestring () Take time (12:12:12)

Date.tolocalestring () Pick up date and time (May 24, 2014 12:12:12)

Convert standard Time format information-2017-10-27 10:20:53

Formatstandard:function (date) {

var myyear = Date.getfullyear ();

var mymonth = Date.getmonth () +1;

var myweekday = Date.getdate ();

var myhour = date.gethours ();

var myminutes = Date.getminutes ();

var myseconds = Date.getseconds ();

if (Mymonth < 10) {

Mymonth = "0" + mymonth;

}

if (Myweekday < 10) {

Myweekday = "0" + myweekday;

}

if (Myhour <10) {

Myhour = "0" + myhour;

}

if (Myminutes <10) {

Myminutes = "0" + myminutes;

}

if (Myseconds <10) {

Myseconds = "0" + myseconds;

}

Return (myyear+ "-" +mymonth + "-" + Myweekday + "" +myhour+ ":" +myminutes+ ":" +myseconds ");

},

5 minutes before taking the time

var date = new Date ();

var date01 = date.setminutes (Date.getminutes ()-1);

var time01 = date.tolocaletimestring ();//Take time (12:12:12)-5 minutes before the time

JS get current time and take value operation

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.