0

I m having a date time text which i m converting to local dateTime using the javascript date time function toString();

 var txt = $(e).html();
     var date = new Date(txt);
     $(e).html (date.toString('yyyy-mm-dd'));

Now the toString method of javascript does not accept any parameters.

It always comes up with this format -

  Tue Aug 26 2014 03:30:34 GMT+0530 (India Standard Time)

I could not change the date format and had to go with a library date.js as here

Any help without any js frameworks.

Regards

Pradyut Bhattacharya
  • 5,440
  • 13
  • 53
  • 83

2 Answers2

0

You can parse it yourself, something like:

var date = new Date(txt);
var dateStr = date.getDate()+'/'+date.getMonth()+'/'+date.getYear();
Kinnza
  • 1,241
  • 10
  • 13
0

1) You can use toLocaleFormat() - MDN. But seems that it supports only in Firefox.

2) Write your own function which will do it. I provide example so you got main idea for it:

function dateFormat(format, date) {
    date = date || new Date();
    return format.replace('%m', date.getMonth());
}

var date = new Date();
console.log(dateFormat('Current month - %m', date));

3) Use libraries.

Eugene Obrezkov
  • 2,910
  • 2
  • 17
  • 34