Convert UTC time to client browser timezone using JavaScript in MVC view
I have a module on my website where registered users can comment on any article. I am storing UTC time
as published time in the database. As per my requirement, I need to show posted time
for comments and time difference
between the published time and the current time (like last seen on Facebook or comment posted on Facebook) with the comment. The marked time should be displayed at Client Browser timezone
.
For example, user XYZ commented 01:00 UTC
and
-
If the XYZ account is registered in India, then the time
timezone
should beIndia Time Zone (UTC+05:30)
6:30 AM. -
If the XYZ account is registered in Singapore, then the time zone should be
Singapore Time Zone(UTC+8:00)
and the time will be 9:00 AM.
To achieve the above, I searched the web and found this post to get the client timezone from the browser , which helped a lot to get the client browser timezone
. (Which I still can't check if it will convert time correctly or not)
Now the main problem is converting UTC time to the given one timezone
(which I get with the solution mentioned here to get the client timezone from the browser ).
Please share your tips.
source to share