<textarea id="runcode35851"><ptml> <body> <script>///<summary>///format display date time///</summary>///<param Name= "X" > The date time to display, such as new Date () </param>///<param name= "y" > The format to be displayed, such as Yyyy-mm-dd Hh:mm:ss</param > Function Date2str (x,y) {var z = {m:x.getmonth () +1,d:x.getdate (), h:x.gethours (), M:x.getminutes (), S:x.getseconds ( )}; y = Y.replace (/(m+|d+|h+|m+|s+)/g,function (v) {return (v.length>1?) 0 ":" ") +eval (' Z. ' +v.slice ( -1))). Slice (-2)}); Return Y.replace (/(y+)/g,function (v) {return x.getfullyear (). toString (). Slice (-v.length)}); Alert (Date2str (New Date (), "Yyyy-mm-dd hh:mm:ss")); Alert (Date2str (New Date (), "yyyy-m-d h:m:s")); </script> </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Time is the current time
Copy Code code as follows:
//1.2013-4-9 11:21:32
//2.2013 year April 9 11:21 32 sec
//3.2013 Year April 9 11 o'clock in the morning 2 1 minutes 32 seconds
//4.2013 year April 9 13:21 P.M. 32 seconds
/*
var thedate = new Date ();
Alert (thedate.getfullyear () + '-' + thedate.getmonth () + '-' + thedate.getdate () + ' + thedate.tolocaletimestring ()) ;
Alert (thedate.tolocaledatestring () + ' + thedate.gethours () + ' dot ' + thedate.getminutes () + ' min ' + thedate.getseconds ( ) + ' seconds ');
if (thedate.gethours () <) {
alert (thedate.tolocaledatestring () + ' a.m. ' + thedate.gethours () + ' dot ' + thedat E.getminutes () + ' min ' + thedate.getseconds () + ' seconds ');
}
Else {
Alert (thedate.tolocaledatestring () + ' PM ' + thedate.gethours () + ' dot ' + thedate.getminutes () + ' min ' + thedate.getseconds () + ' seconds ');
}
*/