AlexK
AlexK

Reputation: 396

Moment.subtract.format does not work for UTC offset

I am trying to subtract one hour, and in this case to get -08:00.

console.log(moment().format('Z')); // -07:00

However when I do the following (I've tried all permutations) it gives me the same result.

console.log(moment().subtract( 1 , "hours").format('Z')); // -07:00

What is the correct usage here?

Upvotes: 0

Views: 578

Answers (1)

imjared
imjared

Reputation: 20554

Z is just going to give you the offset from UTC in your timezone. I'm guessing you're in California or somewhere in PST.

Try this:

moment().format('HH') // "20" for me in EST

versus

moment().subtract( 1 , "hours").format('HH'); // "19" for me in EST

This should give you what you're looking for, hopefully.

Upvotes: 2

Related Questions