Sri Kadimisetty
Sri Kadimisetty

Reputation: 1982

How to get a date in json date format?

I am storing some information in a handwritten json file. One of the fields is a date (of which I need the month & year only.)

In the front end Im employing my JS Frameworks builtin conversion function to present that date into a more human readable format.

My question - 1. How do I get that json date in the first place. Is there a node or web app that can simplify conversions. 2. If I only need the month+year, is there a good way to ignore certain parts of the json date to forget about the specific date inside month and time?

Ref:
http://docs.angularjs.org/api/ng.filter:date

The Json itself is something simple like this -

[
 {
  "title": "One Dummy Book",
  "authors": "One Dummy Author",
  "pubdate": XXXXX
 },
 {
  "title": "Another Book",
  "authors": "Another Author"
  "pubdate": XXXXX
 }
]

How should I write down my publication date or pubdate

Upvotes: 0

Views: 297

Answers (1)

Sean Kinsey
Sean Kinsey

Reputation: 38046

Unfortunately, there's no specification for the serialization and deserialization of dates in JSON, so this is really up to you.

You can either standardize on using the unix timestamp, or a more readable value such as ISO-8601, and depending on whether you need your reviver to automatically be able to revivie the value as a Date, you might also need to add some kind of prefix or pattern that designates this as a date - eg '//date//1350157276920//date//' or similar.

Since you only need the month and the year, using ISO-8601 syntax might be easier as it is simply 'yyyy-mm'.

Upvotes: 1

Related Questions