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.
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.
You can use this very useful little library:
Example:
moment("2013-05-07T11:04:00+05:30", "MMMM Do YYYY, h:mm:ss a");
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.
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:
Number
and then pass to the Date
constructor taking separate components.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");