0

I'm getting date from JSON as string in the following format:

2015-01-03 02:30:00

I want to show it as: 3-Mar-2015 02:30 AM

Any idea, couldn't find elsewhere

Thanks

Ashutosh
  • 4,371
  • 10
  • 59
  • 105
  • 3
    possible duplicate of [Format a Microsoft JSON date?](http://stackoverflow.com/questions/206384/format-a-microsoft-json-date) – Bram May 04 '15 at 17:02
  • May be you can use http://momentjs.com/ ( a library for Parse, validate, manipulate, and display dates in JavaScript) – Abdel Raoof Olakara May 04 '15 at 17:04
  • [Where can I find documentation on formatting a date in JavaScript?](http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) JavaScript doesn't currently have a standard, built-in option for specifying a format pattern. You'll either have to define it yourself or use a library. – Jonathan Lonowski May 04 '15 at 17:08

1 Answers1

1

The data is a little confusing to what you are wanting to output. You said 2015-01-03 02:30:00 should be 3-Mar-2015 02:30 AM but that isn't what it will be. I assume this to be typical DB datetime field (without timezone) as YYYY-MM-DD format. So the 2015-01-03 is really 3-JAN-2015 If this is the case then the following is true.

Please give moment js a try. http://momentjs.com/

With moment it would be something like this...

function dateToStringFormat (date) {
  return moment(date).format('D-MMM-YYYY h:mm a');
}
nickmenow
  • 74
  • 6