-1

How to split the below date format into day date and time.

Date Format is like "2013-05-07T11:04:00+05:30" I want to display above date like "Tue,7 May 2013, 11.04AM". Please suggest how to do this in java script or jquery

Thanks in Advance.

2

4 Answers 4

2

You can use this very useful little library:

http://momentjs.com/

Example:

moment("2013-05-07T11:04:00+05:30", "MMMM Do YYYY, h:mm:ss a");
Sign up to request clarification or add additional context in comments.

2 Comments

I have used moment as shown in above. i used alert to print.i got "61535982570000". My code is like this " var date=moment("2013-05-07T11:04:00+05:30", "MMMM Do YYYY, h:mm:ss a"); alert(date); The date i am getting dynamically.
Try with the format function: moment("2013-05-07T11:04:00+05:30").format("dddd, MMMM Do YYYY, h:mm:ss a");
1

You might be able to use Date.parse(string), but there is no way to determine what date/time formats a particular JavaScript implementation supports.

Otherwise:

  • Use a regex to break up (and validate) the string, convert each string component into a Number and then pass to the Date constructor taking separate components.
  • Use a library that implements the previous option (eg. see other answer).

1 Comment

Any JavaScript implementation that supports ECMAScript 5 will support ISO8601 formatting passed to Date.parse(), however others may or may not support this feature (such as IE<=8). For actually formatting the string, using a custom function is recommended, as the native Date methods are implementation dependent in their formatting of dates.
1

You should work with the native Date Object - this is the easiest way to handle the string.

You can do the following:

var date = new Date("2013-05-07T11:04:00+05:30");

now you have several Date methods you can use to format your string and get the information you need, e.g. what you want is:

date.toUTCString()
// output:
"Tue, 07 May 2013 05:34:00 GMT"

You also could use a regex or an external library, but probably the best way (imo!) is to simply work with the Date Object.

Comments

0

moment.js could be a good choice for you, for example:

Actual moment:

moment().format('MMMM Do YYYY, h:mm:ss a');

Format:

moment("2013-05-07T11:04:00+05:30", "MMMM Do YYYY, h:mm:ss a");

Comments

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.