Currently, I am developing an application using Nextjs 13.4 where the user can create meals and see them in a calendar and list form. If today's date matches the date of the meal, then the meal will be displayed.
I've been having some issues with new Date() because after 5pm Pacific Time, the new Date() will be equal to tomorrow's date. Most likely this is isn't the best way to make sure to get the correct date no matter what time it is, but this is currently working in development:
const todayDate = new Date(new Date().toLocalDateString()) // new Date('yyyy-mm-ddT07:00:00.000Z')
However, when I deployed the application on vercel, it is giving me the incorrect date after 5pm Pacific Time. I have also created a simple website displaying the issue. The website shows a server component and a client component. From this, I can see that the server component is always showing the incorrect date, while the client component is only showing the incorrect date when using new Date().toISOString().
I would like to know what would be the best approach to get the correct date. I assume one approach is to change the component to client, but I would like to keep it as server component. Also, please feel free to correct my method of getting today's date.
here is the link to the simple website.
Thank you