Search code examples
asp.netgridviewtimezonelocal

Display DateTime in GridView using user's time


I have a DateTime stored in UTC time that I'd like to display to the user in their local time from within a GridView control. How can I convert my DateTime to the user's time (not my server's local time)? Here is my current field as it appears in the GridView Columns collection:

<asp:BoundField DataField="RunTime" HeaderText="Run Time"
  SortExpression="RunTime" DataFormatString="{0:f}" />

Solution

  • You would need to know the user's time zone - for example, from profile or user data your website keeps. Alternatively, you can try to guestimate based on GeoIP data, although that can be suspect because the user may not be using that particular time zone on their computer.

    .NET does not automatically know what time the user is using on the remote end.