My server's machine timezone is in HST format. When I try to get the timezone by using HTTP request in JavaScript, it is giving me in UTC format. Is there any way to get the server's timezone.
A few things:
Send the UTC time to the client, and use JavaScript to convert from UTC to Local time. The JavaScript Date
object is sufficient for this, but you may also find libraries like Moment.js and others useful.
Determine the client's local time zone by some other means, either by asking the user, or by guessing. See this answer for more detail. Once you have the time zone ID (such as America/Los_Angeles
, etc.) use this on the server-side. This approach is only useful if you have a lot of date/time manipulation to do on the server-side. If you are simply converting to local time for display, prefer option 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With