0

I have a asp:GridView and it has a asp:BoundField that contains DateTime data comming form database. now here i want to show this DateTime to my local GMT DateTime only for view purpose.

I think it should need a client side solution.

source is below,

 <asp:BoundField HeaderText="Registration Date" DataField="RegisteredDate" DataFormatString="{0:MM/dd/yyyy hh:mm:ss}" />

here RegisteredDate is the CurrentDateTime from database under DataField

Any help will be appreciated.

Rezoan
  • 1,745
  • 22
  • 51
  • GMT is only local if you live in Greenwich. Do you want the date displayed in the local time of the user or in UTC (which is the same as GMT)? – gilly3 Jul 21 '13 at 09:10
  • every user who have visited the page should see the datetime to their Local time @gilly – Rezoan Jul 21 '13 at 09:12
  • Did you read my requirement @Aristos – Rezoan Jul 21 '13 at 10:38
  • 1
    @Rezoan, thanks for clarifying that is SHOULD be client side. Can you tell us why? It is normally advised to do this kind of processing on the server. What if Javascript is disabled on client? – davy Jul 21 '13 at 10:45
  • every user who have visited the page should see the actual datetime to their Local time does it makes sens to you? @davy – Rezoan Jul 21 '13 at 10:50
  • this page is visited by specific registered user. they all have javascript enabled if required. @davy – Rezoan Jul 21 '13 at 10:52
  • Someone edited the question and by the way this question does not have the answer on http://stackoverflow.com/questions/179940/c-sharp-convert-utc-gmt-time-to-local-time – Rezoan Jul 21 '13 at 10:55
  • The other question says to use `DateTimeOffset` because you need to know the time zone of the date in the database. Do you? You can do this server-side if you know the time zone of the client. Do you? – Dour High Arch Jul 21 '13 at 16:00

2 Answers2

2

You can try it by using label below and Time Zone Conversions in c#

<asp:TemplateField HeaderText="Registration Date">
<ItemTemplate>
<asp:Label runat="server" Text='<%#Convert.ToDateTime(Eval("RegisteredDate")).ToLocalTime()%>'/>
</ItemTemplate>      
</asp:TemplateField>
Janty
  • 1,708
  • 2
  • 15
  • 29
  • I am using this method, and it appears to be converting on the server side. I am sending UTC DateTime to the GridView. My server is in Denver, and I'm in Atlanta. It should be showing 8:25 PM but is showing 6:25 PM. Was this meant to do the conversion on the client side? – pwrgreg007 Mar 13 '14 at 00:25
1

I've no experience with the asp controls but if you want a server side solution, this may help: C# - Convert UTC/GMT time to local time or the gridview specific stuff here: asp.net forum.

EDIT - an alternative link How to: Display Localized Date and Time Information to Web Users

I'm sorry, if you still think server side processing wont work after reading that post.

If you wanted to format client-side the moment.js ibrary might be of use.

Community
  • 1
  • 1
davy
  • 4,474
  • 10
  • 48
  • 71
  • I don't think the server side solution will work. – Rezoan Jul 21 '13 at 10:29
  • the problem i am facing should need a cliet side solution. – Rezoan Jul 21 '13 at 10:36
  • @Rezoan, I said it might help. Why don't you think its helpful? – davy Jul 21 '13 at 10:37
  • @Rezoan, you may want to state that in your question next time. – davy Jul 21 '13 at 10:39
  • I am edited my question. for your information if a datetime came form db and when client visited form different timezone what do you think server side would work? – Rezoan Jul 21 '13 at 10:43
  • i said, i want to show this DateTime to my local GMT DateTime only for view purpose. what that it mean to you? – Rezoan Jul 21 '13 at 10:44
  • @Rezoan, look at edit above. Sorry if this doesn't help you, I have now tried to point you to helpful server and client alternatives so I'm clear out of ideas of what you want. You will need to adapt the material in these links. – davy Jul 21 '13 at 11:05
  • thanks. im trying this and let you know the updates. – Rezoan Jul 21 '13 at 11:17
  • "How to: Display Localized Date and Time Information to Web Users" helps. :) – Rezoan Oct 03 '13 at 12:47