Moshe Shaham
Moshe Shaham

Reputation: 15984

Control how angularjs converts date to json string

I have an object containing a javacsript date. Something like this:

var obj = {
  startTime: new Date()
  ....
}

When Angularjs converts the object to JSON (for example, when sending it over $http), it converts the date to a string such as:

2015-12-20T15:35:15.853Z

I would like to have a timestamp instead of this string. What is the best way to achieve this?

Upvotes: 0

Views: 66

Answers (1)

Tarun Dugar
Tarun Dugar

Reputation: 8971

Use the getTime() method to get a unix timestamp from a Date object:

var obj = {
    startTime: (new Date()).getTime()
}

Upvotes: 3

Related Questions