Javascript format date -


this question has answer here:

i having hardest time trying format ie 8+, code works in google chrome, dies in ie. can shed little light.

2013-04-08t10:33:05.427 <-- format month day year time am/pm 

when know time format can make 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" 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -