Home  >  Article  >  Web Front-end  >  Date implementation method in js

Date implementation method in js

小云云
小云云Original
2018-03-19 17:03:311353browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn