var date = new Date (); function Datedemo () { var day; var x = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var d = new Date (); Day = Date.getday (); Return (X[day]); } function Timedemo () { var h, M; var t = ["Morning", "PM"]; h = date.gethours (); m = h-12; return m? T[1]: t[0]; } Alert (date.getfullyear () + "-" + (Date.getmonth () + 1) + "-" + date.getdate () + "" + Datedemo () + "" + timedemo () + "" +date.gethours () + ":" + date.getminutes () + ":" + date.getseconds ());
Alert (date.tolocalestring ()); The Date type also overrides the toLocaleString (), toString (), and valueof () methods, but the values returned by these methods are different from the methods in other types. The toLocaleString () method of the date type returns the date and time in the format appropriate to the locale of the browser (date.todatestring ())//Alert (date.totimestring ()); Alert (date.tolocaledatestring () + datedemo () + date.tolocaletimestring ());
Time Date format