techPackets
techPackets

Reputation: 4506

Setting the timezone in my web app

I am implementing a timer of n minutes for an event using a jquery plugin as a timer library.

The plugin method expects a finaltime to countdown to, so I am passing the time from the server as the final future time to the client. The plugin compares the server provided time with the client time & starts the countdown.

I am using java Calender class for getting the server time.

The functionality will run fine for a client in my timezone but what if the client is in some other timezone or in a daylight saving.

Should I first fetch the timezone from the client to the server then make modifications in the server time then pass it to the client?

I was wondering what would be the correct approach for this.

Upvotes: 0

Views: 53

Answers (1)

Matt Johnson-Pint
Matt Johnson-Pint

Reputation: 241603

  1. Use UTC for the calculation, not local time.
  2. Don't trust the time on the client - it can be changed easily.
  3. If you already know the number of minutes before the event, just calculate it all on the server and pass a whole number of milliseconds down the the client. You can then just use regular javascript timing functions.

Upvotes: 1

Related Questions