dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

dayjs() returns wrong time on Android React Native

Open SeongwoonHong opened this issue 3 years ago • 1 comments

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)

SeongwoonHong avatar Jun 13 '22 22:06 SeongwoonHong

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.

BePo65 avatar Jun 26 '22 05:06 BePo65