DEV Community


Discussion on: Two string methods every JavaScript developer should know.

danstur profile image
danstur • Edited

What happened here is that you got a datetime object formatted as json. So yes you could manually parse the json (it is pretty trivial after all), but there's a built-in solution to handle this: JSON.parse().

After you've done that you'll have to deal with the fact that JavaScript's datetime library is about as bad as possible. So instead of dealing with the catastrophe that the built-in API is, simply use moment.js. Which combined results in the rather pleasant moment(JSON.parse(inputStr)).format('YYYY-MM-DD')

(You should obviously do error handling along the way).