import dayjs from "dayjs";
console.log(dayjs().startOf('day').format()) // 2024-06-21T00:00:00+08:00
console.log(dayjs().startOf('day').toString()) // Thu, 20 Jun 2024 16:00:00 GMT
The time in format()
is correct.
The time printed by toString()
is totally wrong.
why?
Actually, they are the same time.
The toString()
function of dayjs
converts date to Greenwich Mean Time.
Your first datetime is on GMT/UTC +08:00, but second one is on GMT +00:00.
Thus, the difference of them is 8 hrs.
Hope this can be helpful.