Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

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