var myDate = new Date();
myDate.getYear(); //Get the current year (2 digits)
myDate.getFullYear(); //Get the full year (4 digits, 1970-????)
myDate.getMonth(); //Get the current month (0-11, 0 represents January)
myDate.getDate(); //Get the current day (1-31)
myDate.getDay(); //Get the current week X (0-6,0 represents Sunday) Why ask about hovertree.com
myDate.getTime(); //Get the current time (number of milliseconds starting from 1970.1.1)
myDate.getHours(); //Get the current number of hours (0-23)
myDate.getMinutes(); //Get the current number of 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
=====================================================================================================
JS method to get the current timestamp - JavaScript to get the current timestamp
JavaScript gets the current timestamp:
The first method:
var timestamp =Date.parse(new Date());
Result: 1280977330000
The second method:
var timestamp =(new Date()).valueOf();
Result: 1280977330748
The third method:
var timestamp=new Date().getTime();
Result: 1280977330748
The first type: the timestamp obtained is to change milliseconds to 000 display.
The second and third are to obtain the timestamp of the current millisecond.
My colleague and I used js to implement a process of displaying the approximate time left for analyzing data, the time always changed to 0, and the result was very strange. Finally, we found that when we got the time, we used the timestamp obtained by Date.parse(newDate()) to change the milliseconds to 000 display, so the time difference calculation is inaccurate.
The time difference can be calculated using the second or third method. http://hovertree.com/menu/javascript/
Call new Date() separately in js, for example document.write(new Date());
The result displayed is: Mar 31 10:10:43 UTC+0800 2012 Time in this format
However, using new Date() to participate in the calculation will automatically convert to the number of milliseconds starting from 1970.1.1
--------------------------------------------------------------------------------------------------------------------------------
Convert a date in string form to a date object
var strTime="2011-04-16"; //Standard date format
var date= new Date(Date.parse(strTime.replace(/-/g, "/"))); //Convert to Data();
var month=date.getMonth()+1; //Get the current month
The comprehensive introduction to obtaining time in js new Date() is the full content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.