Reputation: 4675
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
Upvotes: 0
Views: 63
Reputation: 74
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');
}
Upvotes: 1