使用用户的时间在 GridView 中显示日期时间 [英] Display DateTime in GridView using user's time

查看:40
本文介绍了使用用户的时间在 GridView 中显示日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以 UTC 时间存储的 DateTime,我想在 GridView 控件中以用户本地时间显示给用户.如何将我的 DateTime 转换为用户的时间(不是我的服务器的本地时间)?这是我在 GridView Columns 集合中显示的当前字段:

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}" />

推荐答案

您需要知道用户的时区 - 例如,从您的网站保存的个人资料或用户数据.或者,您可以尝试根据 GeoIP 数据进行推测,尽管这可能令人怀疑,因为用户可能未在其计算机上使用该特定时区.

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 不会自动知道用户在远程端使用的时间.

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

这篇关于使用用户的时间在 GridView 中显示日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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