-2

Fri Nov 28 2014 16:00:00 GMT 0530 (India Standard Time) to 2014-11-28 16:00:00 I want the conversion to be in javascript only. In php some minutes goes up and down when i m using

date('Y-m-d H:i:s', strtotime(Wed Nov 26 2014 04:30:00 GMT 0530 (India Standard Time))); gives me : 1970-01-01 05:30:00.

date('Y-m-d H:i:s',time(Wed Nov 26 2014 03:30:00 GMT 0530 (India Standard Time))); gives me 2014-11-26 17:32:04

2mins and 4secs are extra.

Thanks.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Arvind Kurmi
  • 19
  • 1
  • 5

2 Answers2

1

Use moment.js

moment().format("YYYY-MM-DD HH:mm:ss")

Something like that.

But you should dig a little bit more around here.. There are many similar questions

http://momentjs.com/docs/#/displaying/format/

victorkurauchi
  • 1,390
  • 18
  • 23
1
var d = new Date("Fri Nov 28 2014 16:00:00 GMT 0530");
console.log(getFormattedString(d));
function getFormattedString(d){
  return d.getFullYear() + "-"+(d.getMonth()+1) +"-"+d.getDate() + ' '+d.toString().split(' ')[4];
  // for time part you may wish to refer http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-string-with-format-hhmmss

}
Amitesh
  • 1,507
  • 1
  • 11
  • 19