Skip to content

Does date-fns work on Nginx servers? #3032

Answered by fturmel
Dhaigh94 asked this question in General
Discussion options

You must be logged in to vote

Hi @Dhaigh94,

I think this is a simple scope issue in your code. The date and zonedDate constants are outside of the function body, so every subsequent call will use the same date.

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);
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Dhaigh94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants