0

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
DisplayName
  • 3,093
  • 5
  • 35
  • 42
jpavlov
  • 2,215
  • 9
  • 43
  • 58
  • 1
    Please do refer http://stackoverflow.com/questions/3552461/how-to-format-javascript-date And http://stackoverflow.com/questions/8888491/how-do-you-display-javascript-datetime-in-12-hour-am-pm-format – bharath Aug 16 '13 at 13:54

2 Answers2

0

Using the Moment.js library:

var day = moment("12-30-2013", "MM-DD-YYYY");

and for further reading use this link.

Colin Brock
  • 21,267
  • 9
  • 46
  • 61
user2502227
  • 495
  • 1
  • 10
  • 23
0

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"
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123