This article mainly shares with you the date implementation method in js, mainly in the form of code. I hope it can help everyone.
1. Simple and clear, just new Date(), and then just follow it:
var myDate = new Date();
myDate.getYear(); //Get the current year (2 digits)
myDate.getFullYear(); //Get the complete year (4 digits, 1970-????)
myDate.getMonth(); //Get the current month (0- 11,0 represents January) // So getting the current month is myDate.getMonth()+1;
##myDate .getDate(); //Get the current day
(1-31)
myDate.getDay(); //Get the current week X (0-6, 0 represents Sunday)
myDate.getTime(); //Get the current time (from 1970.1.1 Starting milliseconds)
##myDate.getHours(); //Get the current hour (0-23)
myDate.getMinutes(); //Get the current minutes (0-59)
myDate.getSeconds(); //Get the current number of seconds (0-59)
myDate.getMilliseconds(); //Get the current number of milliseconds (0-999)
myDate.toLocaleDateString(); //Get the current date
var mytime=myDate.toLocaleTimeString(); //Get the current time
##myDate.toLocaleString( ); //Get date and time
The above is the detailed content of Date implementation method in js. For more information, please follow other related articles on the PHP Chinese website!