Ahmed Khalid

Ahmed Khalid

  • NA
  • 114
  • 5.5k

DateTime Conversion for Gridview

Feb 3 2023 7:51 PM

Hi, 

I have a GridView that has a timestamp in it and server is in remote location having time other than client timings. I have implemented the time conversion method using template in gridview as shown below. The time is still being displayed as server time. Any idea I can try?

NB: Local time is 2/3/2023 01:34 AM and Server Time is showing as 2/3/2023 8:04:00 AM

Many thanks

<asp:TemplateField HeaderText="Time Stamp" ItemStyle-Width="200">
   <ItemTemplate>
        <asp:Label ID="lbl_TimeStamp" runat="server" Text='<%# Convert.ToDateTime(Eval("TransTimeStamp", "{0:g}")).ToLocalTime() %>'></asp:Label>
   </ItemTemplate>
</asp:TemplateField>

 


Answers (7)