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; }