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

3

1 Answer 1

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');
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, just came to know about moment.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.