I am having the hardest time trying to format this for IE 8+, my code works in google chrome, but dies in IE. Can someone shed a little light.
2013-04-08T10:33:05.427 <-- format to Month day year time AM/PM
I am having the hardest time trying to format this for IE 8+, my code works in google chrome, but dies in IE. Can someone shed a little light.
2013-04-08T10:33:05.427 <-- format to Month day year time AM/PM
Using the Moment.js library:
var day = moment("12-30-2013", "MM-DD-YYYY");
and for further reading use this link.
When you know your time format that well you can make a pretty garenteed regexp:
/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.+)/
Code:
var str = "2013-04-08T10:33:05.427";
str = str.replace(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.+)/, function(_, y, m, d, h, mi, s) {
var amPm;
if ( h < 12 ) {
amPm = 'am';
} else {
amPm = 'pm'; h-=12;
}
return [m, ' ', d, ' ', y, ' ', h, ':', mi, ':', s, ' ', amPm].join('');
});
str; // "04 08 2013 10:33:05 am"