Konstantin Ruzhev
Konstantin Ruzhev

Reputation: 1

React Moment Offset Issue

I am using react moment library to format my time however I keep getting the time offset added to it. There is nothing in the docs to explain how to give you the local date so I was wondering if anyone can help.

So what I am trying is:

<Moment format="HH:mm" utc tz="Europe/London" date="2020-04-08T21:00:00.000Z" local> </Moment>

I have tried different combinations between them all but nothing seems to be working. The utc is not mentioned in docs but I have seen other stack overflow posts where its suggested.

Please help

Upvotes: 0

Views: 691

Answers (2)

xehpuk
xehpuk

Reputation: 8241

Try this:

<Moment format="HH:mm" date="2020-04-08T21:00:00.000Z" utc/>

There's no documentation on the utc prop but it does what you expect:

<time datetime="1586379600000">21:00</time>

Upvotes: 0

Idin Khayami
Idin Khayami

Reputation: 252

I suggest you use the moment library instead of react moment or any of the other libraries.

npm install moment --save
npm install moment-timezone
const timezone="America/Los_Angeles";
const date="2020-04-08T21:00:00.000Z";
moment().tz(timezone).format(date);

Upvotes: 1

Related Questions