Sorry, but what is the fastest way to display the current date?
2014-01-18 Saturday 12:30
with this function or how do it the right way?
var d=new Date();
var t=d.getTime();
Try
var d = new Date();
var dd = d.getDate();
var mm = d.getMonth()+1; //January is 0!
var yy = d.getFullYear();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
var day=weekday[d.getDay()];
var h = d.getHours();
var m = d.getMinutes();
alert(yy+"-"+mm+"-"+dd+" "+day+" "+h+":"+m)
var d = new Date();
alert(d.toString());
If you don't mind the format, you can do it in one line:
''+new Date()
You only need to use a Date object as a string, in order to implicitly call its .toString() method, which
returns a String value. The contents of the String are implementation-dependent, but are intended to represent the Date in the current time zone in a convenient, human-readable form.
Date().valueOf();Date MDN