------------------------------------------------------------------------------------JS Gets the current datetime format as YYYY-MM-DD hh: Mm:ss
Date.prototype.format = function (format) {var args = {"m+": This.getmonth () + 1, "d+": This.getdate (), "H +": This.geth Ours (), "m+": This.getminutes (), "s+": This.getseconds (), "q+": Math.floor ((This.getmonth () + 3)/3),//quarter
"S": This.getmilliseconds ()}; if (/(y+)/.test (format)), format = Format.replace (regexp.$1, (this.getfullyear () + ""). substr (4-regexp.$1.length)); for (var i in args) {var n = args[i]; if (New RegExp ("(" + i + ")"). Test (format), format = Format.replace (regexp.$1,regexp.$1 . length = = 1? N: ("xx" + N). substr (("" + N). length);} return format;};
Calling methods
Alert (new Date (). Format ("Yyyy-mm-dd hh:mm:ss:s"));
------------------------------------------------------------------------------------
function Getnowformatdate () {
var date = new Date ();
var seperator1 = "-";
var Seperator2 = ":";
var month = Date.getmonth () + 1;
var strdate = Date.getdate ();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strdate >= 0 && strdate <= 9) {
Strdate = "0" + strdate;
}
var currentdate = date.getyear () + seperator1 + month + Seperator1 + strdate
+ "" + date.gethours () + Seperator2 + date.getminutes ()
+ Seperator2 + date.getseconds ();
return currentdate;
}
------------------------------------------------------------------------------------
function Curdatetime () {var d = new Date (), var year = D.getyear (), var month = D.getmonth () +1; var Date = D.getdate (); var Day = D.getday (); var hours = d.gethours (); var minutes = d.getminutes (); var seconds = d.getseconds (); var ms = D.getmilliseconds (); var curdatetime= year;if (month>9) curdatetime = Curdatetime + "-" +month;elsecurdatetime = curdatetime + "-0" +month;if ( date>9) Curdatetime = Curdatetime + "-" +date;elsecurdatetime = curdatetime + "-0" +date;if (hours>9) CurDateTime = Curdatetime + "" +hours;elsecurdatetime = Curdatetime + "0" +hours;if (minutes>9) curdatetime = CurDateTime + ":" +minutes ; elsecurdatetime = curdatetime + ": 0" +minutes;if (seconds>9) curdatetime = Curdatetime + ":" +seconds;elsecurdatetime = Curdatetime + ": 0" +seconds;return curdatetime; }alert (Curdatetime ());
--------------------------------------------------------
JS gets the current datetime format of YYYY-MM-DD HH:MM:SS