Question About DayJS Date Formatting
Hey everyone, sorry for the "just google it lol" question but I've tried searching around and can't find anything. I am trying to parse a date using dayJS with the following code. However, it returns invalid date. Could anyone point me in the right direction on how I could solve this? Thanks!
5 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Although not directly an answer to your question... I only use UTC to display the date string, but when saving it somewhere (like DB) I use the ISO string format.
ISO can easily be parsed to dayjs() and you can add the timezone offset depending on the user's timezone. And then you won't have the problem you have now.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ISO is zero timezone offset. So technically GMT-0.
Although this article says to use with timezone I find impractical... So I just use the ISO format.
Actual example of that from my app -->
When a user registers, they get a activation code which is valid for 1h. If I insert the date I get from my client, it will have the clients timezone which will then be saved to db. But then when I check if the activation code is still valid, I do it on the server. But what happens if the server's timezone is different than the user's? Then the timezones get mixed and we got a problem. Which is why I always use ISO, then it's easy to get the timezone offset.
Might not be the prettiest, but it works.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View