Which to use in oder to get current time in javascript, Date() or new Date()? -


if passing current time argument function, way correct, date() or new date()? take following code example, 1 better?

function logtime(time) {     console.log(time); }  //one var = new date(); logtime(now);  //two logtime(new date());  //three logtime(date()); 

it's better use new date, because real date object.

> var d = date(); undefined > d 'thu aug 01 2013 02:22:19 gmt+0200 (cest)' > typeof d 'string' 

date, when used normal function, returns string. when used constructor, returns object having date prototype, can use methods gettime, getseconds etc.

> d = new date(); thu, 01 aug 2013 00:24:41 gmt > typeof d 'object' > d.gettime(); 1375316681520 > d.getseconds(); 41 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -