如何在datagridview中将UTC datetime列转换为本地时间? [英] How to convert UTC datetime column to local time in datagridview?

查看:147
本文介绍了如何在datagridview中将UTC datetime列转换为本地时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个新的日志记录数据库,我决定使用UTC datetime存储所有的datetime值,因为我们公司跨越时区,多个来源和时区正在记录事件。这是非常有用的。



但是,我无法让我头脑的问题是在我的用户应用程序的datagridview中格式化数据时间。



我们的应用程序主要使用LINQ to SQL来处理通用SQL CRUD调用中的数据,所以我希望我可以屏蔽/格式化DGV以获取转换或一些LINQ函数,而不必编写特殊的SQL存储过程每次需要显示数据时都会这样做(我已经找到多个来源来解释如何做到这一点)



提前谢谢。试图给出尽可能多的信息,我可以想到,但如果我缺少某些东西,请让我知道。



将喜欢VB.NET中的答案,但C#工作很好(完全在两个,这个程序恰好恰好在VB.BET中)

解决方案

在你的RowCreatedEvent中,您应该可以使用以下功能: TimeZoneInfo.ConvertTimeFromUtc



请参阅Microsoft文档中的一些很好的例子(in两个Vb& C#):



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


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)

解决方案

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

这篇关于如何在datagridview中将UTC datetime列转换为本地时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆