The time object is an object that we often use, and it is inseparable from this object whether it is time output, time judgment and other operations. In addition to the time objects in JavaScript, there are also many time objects in VbScript, and they are very useful. The following is to explain the date function in JavaScript according to our process.
new Date()
new Date(milliseconds)
new Date(datestring)
new Date(year, month)
new Date(year, month, day)
new Date(year, month, day, hours)
new Date(year, month, day, hours, minutes)
new Date(year, month, day, hours, minutes, seconds)
new Date(year, month, day, hours, minutes, seconds, microseconds)
The following is the
1.new Date(), when there are no parameters, the current time and date object is created.
2.new Date(milliseconds), when the parameter is a number, then this parameter is a timestamp, which is regarded as milliseconds, creating a time and date object with a specified milliseconds from January 1, 1970.
3.new Date(datestring), this parameter is a string, and this string must be converted using Date.parse().
4. The following six constructors are precisely defined:
1).year is an integer. If it is 0-99, then add 1900 on this basis, and the others are returned as it is.
2).month, is an integer with a range of 0-11.
3).day is an integer with a range of 1-31.
4).hours is an integer with a range of 0-23.
5).minutes, is an integer with a range of 0-59.
6).seconds is an integer with a range of 0-59.
7).microseconds is an integer with a range of 0-9999.
<html><head><title>Convert timestamps to year, month, day, time, minute, and second</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head><body></body></html><script>window.onload=function(){var now=new Date();//Current system time var shijianchuo = now.getTime();//Get the current timestamp alert("timestamp:"+shijianchuo);var nowdate = new Date(shijianchuo);//Convert timestamps to date object var Nowtime=nowdate.Format("yyyy-MM-dd hh:mm:ss");//Format the current system time, which is equivalent to converting the timestamp to year, month, day, hour, minute, and second. Alert("current time:"+nowtime);}/*Date formatting: For the extension of Date, converting Date into a String year (y) in the specified format can use 1-4 placeholders, and quarter (q) can use 1-2 placeholders. Month (M), day (d), hour (h), minute (m), and seconds (s) can use 1-2 placeholders. Milliseconds (S) can only use 1 placeholder (a number of 1-3 digits) Example: (new Date()).Format("yyyy-MM-dd hh:mm:ss.S")(new Date()).Format("yyyy-MM-dd hh:mm:ss.S milliseconds qq quarter")*/Date.prototype.Format = function (fmt) { var o = {"M+": this.getMonth() + 1, //month"d+": this.getDate(), //day"h+": this.getHours(), //time"m+": this.getMinutes(), //min"s+": this.getSeconds(), //seconds"q+": Math.floor((this.getMonth() + 3) / 3), //Quarterly "S": this.getMilliseconds() //ms};if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));for (var k in o)if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));return fmt;}</script>