dayjs
dayjs copied to clipboard
dayjs() returns wrong time on Android React Native
Describe the bug when I do
import dayjs from 'dayjs';
dayjs.tz.setDefault('America/New_York');
const datenow = dayjs();
I get something like "2022-06-13T21:00:00.000Z" which is incorrect time. the correct time is 06:03 PM. However, if I do
datenow().hour() -> 6
datenow().minute -> 3
this is correct. Please let me know how to get correct current time
Expected behavior A clear and concise description of what you expected to happen.
Information
- Day.js Version [e.g. v1.0.0] 1.11.0
- OS: [e.g. iOS] Android (React Native)
- Browser [e.g. chrome 62]
- Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]. EST (New York)
To use the newly set default timezone you have to parse the value with const datenow = dayjs.tz(); (or giving a date string as a parameter to .tz).
See also the corresponding documentation.