Home > Asp.net MVC > How to get client machine datetime with local timezone offset value

How to get client machine datetime with local timezone offset value

This article will help to understand how to get  client machine’s datetime with local timezone offset value.

Use javascript method getTimezoneOffset() and assign it’s value to hidden field in .cshtml file as shown in below code. Then pass this value to mvc controller.

In the above code, variable offset will have the value which is the difference, in minutes, from local time to UTC. Note that this means if offset is positive the local timezone is behind UTC and negative if it is ahead.
Hence if client machine is in India then offset value will be (-330) and local timezone offset value will be (+05.30).

To get client machine’s datetime value with local timezone offset like (2019-04-04 11:05:41.31 +05:30) in controller refer the following code :

In the  above code timeZoneoffset is offset value from javascript function.

This Article is TAGGED in , . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">