0

I have a json date like /Date(1334514600000)/ in my response and when I convert it in javascript then I got this date Tue Apr 17 2012 11:37:10 GMT+0530 (India Standard Time), but I need the time format like 11:37:10 and I fail every time. Can anyone tell me how can I resolve it?

4 Answers4

0

Try this

yourdateObj.toLocaleFormat('%H:%M:%S')

EDIT : This works only in firefox.

Akhil
  • 2,494
  • 20
  • 35
0

The most reliable cross browser way I've found is

new Date().toTimeString().split(' ')[0]

Tested in latest Firefox, Chrome, IE11 (not tested in any other IE) and Edge

To be perfectly honest, it may seem overkill, but if you deal with dates, I recommend not re-inventing the wheel, use something like moment.js - it has support for timezones as well - it's never let me down (yet)

Jaromanda X
  • 47,382
  • 4
  • 58
  • 76
0

How about Date#toLocaleTimeString with proper locale?

console.log(new Date().toLocaleTimeString('in')); 
barbsan
  • 3,238
  • 11
  • 18
  • 27
0

Finally got the answer:-

function DateConvert(JsonDate) { var date = new Date(parseInt(JsonDate.substr(6))); date = date.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true }); return date;