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,466
  • 8
  • 24
  • 45
user1234
  • 2,750
  • 3
  • 37
  • 83

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,140
  • 10
  • 21