How to convert UTC datetime column to local time in datagridview?

牧云@^-^@ 提交于 2019-12-04 04:26:45

问题


I am doing work on a new logging database that I have decided to use UTC datetime to store all datetime values since our company spans timezones and multiple sources and timezones are logging events. That is working great.

However the problem that I cannot get my head around is formatting the datetimes in my datagridview for my user application.

Our applications use mostly LINQ to SQL to manipulate our data from generic SQL CRUD calls, so I am hoping I can mask/format the DGV to get the conversion or some LINQ function rather than having to write special SQL stored procedures to do it every time I need to display the data.. (I have found multiple sources that explain how to do that)

Thank you in advance. Tried to give as much information as I can think of, but if I am missing something, please let me know.

Would love the answer in VB.NET, but C# works great as well (versed fully in both, this app just happens to be in VB.BET)


回答1:


In your RowCreatedEvent, you should be able to use the function: TimeZoneInfo.ConvertTimeFromUtc

See the Microsoft documentation for some good examples (in both Vb & C#):

http://msdn.microsoft.com/en-us/library/system.timezoneinfo.converttimefromutc.aspx



来源:https://stackoverflow.com/questions/7265092/how-to-convert-utc-datetime-column-to-local-time-in-datagridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!