-
I am having issues with date-fns where I deploy my app to a Nginx server and it is sending the correct dates but the next day it is sending the incorrect dates unless I redeploy my code. Is there a way for date-fns to grab the current date and time when the function is called while it is on a server? My code example is
|
Beta Was this translation helpful? Give feedback.
Answered by
fturmel
May 14, 2022
Replies: 1 comment
-
Hi @Dhaigh94, I think this is a simple scope issue in your code. The Try something like this instead: const { utcToZonedTime, format } = require('date-fns-tz');
const timeZone = 'Australia/Sydney';
const pattern = 'dd-MM-yyyy';
function todaysDate() {
const zonedDate = utcToZonedTime(new Date(), timeZone);
return format(zonedDate, pattern);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Dhaigh94
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @Dhaigh94,
I think this is a simple scope issue in your code. The
date
andzonedDate
constants are outside of the function body, so every subsequent call will use the same date.Try something like this instead: