Javascript: basic usage of Date object
This article code from w3school: http://www.w3school.com.cn
1. Get the current date:
document.write("Current time: "+new Date());
2. Obtain the timestamp in milliseconds ):
document.write(new Date().getTime());
3. Set year, month, and day (required for the Year, and optional for the month and day ):
var d = new Date(); d.setFullYear(2012,3,16) document.write(d); document.write("
"); document.write(d.getTime());
4. Return the current day of the week:
document.write(new Date().getDay())
5. Comparison of date objects:
Function compareDate () {var oneday = new Date (); oneday. setFullYear (, 26); var currentday = new Date (); if (oneday
:
Sample Code:
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink">
VcD4KPHA + PC9wPgo8cHJlIGNsYXNzPQ = "brush: java;">
Javascript date object
(1) return the current date <script> document. write ("Current time:" + new Date (); </script> (2) return timestamp (millisecond) <script> document. write (new Date (). getTime (); </script> (3) set year, month, and day <script> var d = new Date (); d. setFullYear (2011,3, 16) document. write (d); document. write ("
"); Document. write (d. getTime (); </script> (4) convert the Date of the current day (based on UTC) to the string <script> var d2 = new Date () document. write (d2.toUTCString () </script> (5) returns the current day of the week <script> var d3 = new Date () var weekday = new Array (7) weekday [0] = "Sunday" weekday [1] = "Monday" weekday [2] = "Tuesday" weekday [3] = "weekday" weekday [4] = "Thursday" weekday [5] = "Friday" weekday [6] = "Saturday" document. write (weekday [d3.getDay ()]) </script> (6) display a time clock
<Script> function startTime () {var today = new Date (); var y = today. getFullYear (); var M = today. getMonth () + 1; var day = today. getDay (); var h = today. getHours (); var m = today. getMinutes (); var s = today. getSeconds (); m = checkTime (m); s = checkTime (s ); var content = (y + "/" + M + "/" + day + "" + h + ":" + m + ":" + s ). fontsize (6 ). fontcolor ("red"); document. getElementById ("time_text "). innerHTML = content; setTimeout ("startTime ()", 500);} function checkTime (I) {if (I <10) {return "0" + I ;} return I ;}</script> (7) Comparison of date objects
2015.3.26 what is the relationship with the current time?
Comparison<Script> function compareDate () {var oneday = new Date (); oneday. setFullYear (, 26); var currentday = new Date (); if (oneday