Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: get current date and time

I'm trying to obtain the current date and time in react native

I have tried like:

const today = new Date()

and it prints me

"2022-03-30T13:13:04.154Z"

but the real mine time is

"2022-03-30T15:13:04.154Z"

with timezone it-IT

I have tried also to use moment but it gives me back the same results "2022-03-30T13:13:04.154Z"

How can I obtain the date and time with timezone?

like image 496
Jack23 Avatar asked Nov 21 '25 18:11

Jack23


1 Answers

ideally creating the date in the way you have done should work.

as for moment:

import moment from 'moment'

moment(today).format('LLLL');

considering that today is the constant new Date(); LLLL is one format, you can try other formats:

moment().format('LT');   // 7:06 PM
moment().format('LTS');  // 7:06:13 PM
moment().format('L');    // 03/30/2022
moment().format('l');    // 3/30/2022
moment().format('LL');   // March 30, 2022
moment().format('ll');   // Mar 30, 2022
moment().format('LLL');  // March 30, 2022 7:06 PM
moment().format('lll');  // Mar 30, 2022 7:06 PM
moment().format('LLLL'); // Wednesday, March 30, 2022 7:06 PM
moment().format('llll'); // Wed, Mar 30, 2022 7:07 PM

this is from the official moment js website

like image 138
Eragon_18 Avatar answered Nov 24 '25 23:11

Eragon_18



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!