Expand my Community achievements bar.

How to get the 'Z' in time?

Avatar

Level 8

Hello

With the below code, am getting current date and time, fine

var date = new Date();

time = date.getHours();

time = time + ":" + date.getMinutes() + ":" + date.getSeconds()

I am getting the output as below,

16:3:24

But, i want like below

16:03:24 EST ......I mean, i need the below enhancements

1) Minutes should come with PREFIX ZERO if minutes are lesss than 10

2) Most importanlty, i need DAY LIGHT ZONE, like Eastern Time, Central time, Pacific time etc.

Pls. let me know in JavaScript?

Thank you

1 Reply

Avatar

Former Community Member

var date = new Date();

this.rawValue = date.toTimeString();

The function toTimeString() handles leading zeroes and includes time zone, for example 18:05:56 GMT-0700 (Pacific Daylight Time).

Steve