0

I'm converting a epoch date into local date:

$("time").each(function() {
    var date = $(this).text(); // gives me "1325419200000"
    newDate = new Date(date); // gives me Invalid Date
});

html:

<td class="date">
    <time datetime="{{date}}">{{date}}</time>
</td>

how can i convert epoch date into local date in the format: 'MMM DD, YYYY h:mm:ss A'. how can i achieve this?

Milap
  • 6,915
  • 8
  • 26
  • 46
user1234
  • 3,000
  • 4
  • 50
  • 102

1 Answers1

1

DateObject won't accept String epoch. so you need to convert it to Integer.

Check this out

var epoch = "1325419200000"
var date = new Date(epoch);
// return Invalid Date

date = new Date(parseInt(epoch));
//return Sun Jan 01 2012 21:00:00 GMT+0900
blurfx
  • 1,270
  • 11
  • 22