Billy Moon Billy Moon - 25 days ago 7x
Javascript Question

Javascript date format like ISO but local

how do I format a javascript date like ISO format, but in local time?


I am getting the time as: "2012-09-13T19:12:23.826Z"

but here, it is 22:13, so how do I include the timezone in above format?

I ended up doing...

pad=function(e,t,n){n=n||"0",t=t||2;while((""+e).length<t)e=n+e;return e}
c = new Date()


AFAIK you can't format dates in javascript (without using external libraries). The best you could do is "format it yourself". I mean:

var date = new Date();
var year = date.getFullYear();
var month = date......

var ISOdate = year + "-" + month + "-" + .... ;

But there are some good libraries that will let you format dates! (read "format" as in library.getDate("YYYY-MM-DD.........");)


Moment.js seems the thing you're looking for: