dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

Poor documentation or bug with local time display as string

Open zehawki opened this issue 3 years ago • 2 comments

console.log(dayjs())

... $M $W $d: Tue Nov 30 2021 19:17:28 GMT+0530 (India Standard Time) $m ...

console.log(dayjs().toString())

Tue, 30 Nov 2021 13:47:28 GMT

Huh? Calling Now shows local time, and calling As String on Now mysteriously turns it into GMT.

So how is one supposed to get a string of the local time?

zehawki avatar Nov 30 '21 14:11 zehawki

I'm was having the same exact issue. This API is insanely inconsistent, and chocked full of gotchas. After 10 months of attempting to make things work, I decided to switch on to Luxon. Wow, massive difference. Each of Luxon's API methods does what you think it will do, and I haven't run into a single gotcha or nonsensical default as of yet. Having an API that can be reasoned about is paramount, especially with a complex topic as date/times.

Strandedpirate avatar Aug 25 '22 17:08 Strandedpirate

toString will do the exactly same as (new Date()).toString() according to your system locale setting

iamkun avatar Aug 26 '22 05:08 iamkun