Javascript Date: date obtained by javascript, year, month, and day

Source: Internet
Author: User
Javascript get date, year, month, day
VaR mydate = new date (); mydate. getyear (); // obtain the current year (2 digits) mydate. getfullyear (); // obtain the complete year (4 digits, 1970 -????) Mydate. getmonth (); // obtain the current month (0-11, 0 represents January) mydate. getdate (); // obtain the current day (1-31) mydate. getday (); // obtain the current day x (0-6, 0 represents Sunday) mydate. gettime (); // obtain the current time (milliseconds starting from 1970.1.1) mydate. gethours (); // obtain the current hour (0-23) mydate. getminutes (); // get the current number of minutes (0-59) mydate. getseconds (); // obtain the current number of seconds (0-59) mydate. getmilliseconds (); // get the current number of milliseconds (0-999) mydate. tolocaledatestring (); // obtain the current date var mytime = mydate. tolocaletimestring (); // obtain the current time mydate. tolocalestring (); // obtain the date and time

New date (year, month, 0). getdate (); // obtain the number of days in the current month

 

Conversion Time Format String

function   getdate() { var now=new Date(); var y=now.getFullYear(); var m=now.getMonth()+1; var d=now.getDate(); m=m <10?"0"+m:m; d=d <10?"0"+d:d; return   y+"-"+m+"-"+d; }

 

Var myDate = new Date (); myDate. getYear (); // obtain the current year (2 digits) myDate. getFullYear (); // obtain the complete year (4 digits, 1970 -????) MyDate. getMonth (); // obtain the current month (0-11, 0 represents January) myDate. getDate (); // obtain the current day (1-31) myDate. getDay (); // obtain the current day X (0-6, 0 represents Sunday) myDate. getTime (); // obtain the current time (milliseconds starting from 1970.1.1) myDate. getHours (); // obtain the current hour (0-23) myDate. getMinutes (); // get the current number of minutes (0-59) myDate. getSeconds (); // obtain the current number of seconds (0-59) myDate. getMilliseconds (); // get the current number of milliseconds (0-999) myDate. toLocaleDateString (); // obtain the current date var mytime = myDate. toLocaleTimeString (); // obtain the current time myDate. toLocaleString (); // obtain the date and time

New date (year, month, 0). getDate (); // obtain the number of days in the current month

 

Conversion Time Format String

function   getdate() { var now=new Date(); var y=now.getFullYear(); var m=now.getMonth()+1; var d=now.getDate(); m=m <10?"0"+m:m; d=d <10?"0"+d:d; return   y+"-"+m+"-"+d; }

 

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.