Format dates in Javascript -
i have log error datetime in file, using next code:
var dlogdate = new date(); console.log(dlogdate.tostring().substring(4) + ', ' + dlogdate.togmtstring().substring(4));
as per above code output comes follows nice not formated need:
"oct 10 2014 12:48:59 gmt+0530 (ist), 10 oct 2014 07:18:59 gmt"
i want result s follows :
"10 oct 2014 12:48:59 (ist), 10 oct 2014 07:18:59 (gmt)"
see date part before ",". need 10 oct instated of oct 10
this can done function substring first 4 character string , concat @ 3rd position again, still curious know if there other simple way this? don't want utilize 3rd party library/script.
thanks.
you can utilize date functions format date
http://www.w3schools.com/jsref/jsref_obj_date.asp
var monthindex = date.getmonth(); var dayindex = date.getday();
var montharray = ['january',....]; var dayarray = ['sunday',...]
console.log(montharray[monthindex] + "-" + dayarray[dayindex]);
javascript date datetime format
No comments:
Post a Comment