- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
TimeZoneInfo.ConvertTimeFromUtc
方法从注册表HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zone
读取夏令时设置来计算本地时间?
如果是这样,它是否只适用于当前时间而不适用于过去的任何年份或日期?我想知道我是否可以将“东部标准时间”(如“2-1-2010 3:00 PM”)中的过去日期时间转换为 GMT 或 UTC遵循 2010 年的 DLS(夏令时)?以另一年为例,例如“2-1-2006 3:00 PM”。当你阅读 here ,美国的 DST 在 2007 年发生了变化。
请问,如果我必须在过去 5 年中显示来自马来西亚和纽约(美国东部标准时间)等两个不同地方的 SQL 数据库的约会时间,最佳解决方案是什么?
最佳答案
Does the
TimeZoneInfo.ConvertTimeFromUtc
method read the daylight saving settings from the registryHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zone
to calculate the local time?
是的,除了最后一个键名是 Time Zones
(你删除了一个 s
)。您可以在 this MSDN blog article 中了解其工作原理。 .
If so, does it work for only the current time and not for any past years or dates?
它将适用于 Windows 注册表数据中存在的任何过去年份。您可以检查注册表中的每个子项,看看您可以为每个区域转换多远。但是,数据中存在各种错误和遗漏。一般来说,此数据的历史准确性不如其他来源(例如 IANA/Olson 时区数据库,您可以通过 Noda Time 使用)。 .在 the timezone tag wiki 中阅读更多内容.
I would like to know if I can convert a past date time in 'Eastern Standard Time' like '2-1-2010 3:00 PM' to GMT or UTC which follows the DLS (Day Light Saving) for the year 2010? Take another year like '2-1-2006 3:00 PM' as an example also. As you read here, the DST has changed in 2007 for the US.
术语是“夏令时”- 没有大写字母,一个单词表示夏令时,缩写为 DST
是的,Windows 时区数据和 TimeZoneInfo
将 DST 考虑在内。
要将 转换为 UTC,您可以使用 ConvertTimeToUtc
,而不是 ConvertTimeFromUtc
。
是的,Windows 知道美国 2007 年夏令时的变化。它确实不但是,了解earlier changes ,例如 Uniform Time Act 之前的值于 1987 年生效。为此,您需要 IANA/Olson 数据库。
May I ask, what is the best solution if I have to display an appointment time from a SQL database in two different locals like Malaysia and New York (USA Eastern Standard Time) for a visitor in the past 5 years?
使用 TimeZoneInfo
为纽约使用 ID “东部标准时间”
ID,为纽约使用 “新加坡标准时间”
ID马来西亚。
在 Noda Time 中使用 IANA/Olson 时区,使用 "America/New_York"
和 "Asia/Kuala_Lumpur"
。
对于您询问的过去 5 年,这两个选项都可以。 Malaysia's last time zone change was in 1982 .
对于过去的事件,将 UTC 时间存储在您的数据库中,或存储具有正确时间和事件时区偏移量的 DateTimeOffset
值(参见 DateTime
vs DateTimeOffset
)。根据显示需要从 UTC 转换为查看者的时区。
为了安排 future 的事件,将事件的本地时间存储在您的数据库中,并遵循 the guidance I've written here .
您还可以在我的 Pluralsight 类(class) Date and Time Fundamentals 中找到有关此主题的扩展指导。 .具体来说,您应该考虑观看标题为“时区”、“.NET Framework 中的日期和时间”和“Noda Time 简介”的部分。
关于c# - TimeZoneInfo 过去几年的时间转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29979609/
我有一些文档,它的创建时间以毫秒为单位。我需要将它们分为今天、昨天、过去 7 天、过去 30 天、超过 30 天。 我使用了以下代码:convertSimpleDayFormat(1347022979
我正在尝试创建一个 Crystal 报告,用于在图表中显示十二个月的月费率。 对于此任务,我有一个 dc_date(mm/dd/yyyy) 作为变量,我将其更改为 mmyyyy 格式。但是当我看到月份
我想使用 Linux 命令将年转换为天(过去)。例如: 用户给出的号码:10年前 程序应计算 10 年前的天数总和(例如:10*12*31(年/月/日)--> 3720 天)。 程序将其与今年开始的当
我的要求有点复杂,为了便于理解,让我用简单的例子说明一下。假设,我们必须计算过去 12 个月消费者按月购买的产品数量。所以我们要做的是: SELECT DATENAME(MONTH, m.Invoic
如果我今天(2012 年 8 月 21 日)运行查询,我想得到这个结果集: [...] 为了得到这个,我正在使用以下内容,但它似乎过于复杂。这可以简化吗? ;WITH Numbers_cte([num
这是我目前用来显示下周五日期的方法。 $date_friday = date('F j', strtotime('Friday')); print $date_friday; 我应该使用什么来显示过去
我有一个包含一个日期时间列的表。我只需要返回过去 6 个月的行。这可以通过 来完成 where datetime_column > DATEADD(m, -6, current_timestamp)
我正在为我的应用使用 Firestore,并且希望能够获得过去 7 天内发布的最受欢迎的项目。在理想的情况下,调用看起来像这样: let calendar = Calendar.cur
我有以下方法来计算时间: public static String sumTime(String date1, String date2) throws ParseException { Ca
我想检索过去 24 小时内发布的观看次数最多的前 10 个主题。如果网站在过去 24 小时内获得的主题少于 10 个,则必须检索前一天剩余的浏览次数最多的主题。 我以unix格式将时间存储在数据库中,
我想从我的 MySQL 服务器获取过去 x 个月的所有记录。例如使用 2 个月(不是过去 2 个月,比如过去 60 天,而是过去整个月等等。如果实际月份是 4 月,我想要 2 月和 3 月的所有记录)
我正在尝试使用 php 创建一个博客系统,我需要一种方法来计算过去 21 天内浏览次数最多的帖子。有人知道这样做的好方法吗? 我对 php 没有太多经验,所以我需要有人给我指出正确的方向。我试图研究
我正在尝试查找过去 26 周每周结束时的用户总数。 例如, 从第 26 周开始,该周有 100 名用户注册,并且有 20 名新用户注册,因此到第 26 周结束时,注册用户数量为 120 名 从第 25
假设我们有下表,列如下所示: Rides ride_id start_time end_time passenger_id driver_id ride
好的,我正在尝试获取过去 24 小时内包含“价格”列的所有行的平均值。 $tickerBuy = $this->model->ticker("date AS datetime, avg(price)
我有一个账户表,其中名为“dateCreation”的列是账户的创建日期。 我想获取过去 12 个月内创建的所有帐户,但有时 2 个月或更长时间都没有创建帐户。在这几个月里,我希望 mysql 返回
是否有办法检索过去 7 天内添加的所有用户?添加用户时,包含时间戳。日期被添加到他们的“信息”中。 例如这样: 因此日期公式为:D/M/YYYY。谁能帮我理解如何做到这一点? PS:奇怪的OL3gee
我有一个 Angualr 服务,可以列出从当前月份开始的 12 个月和年份: JS: app.factory('12months', function() { return {
我有一个弹出窗口,其中一个名为 fade 的元素应该扩展到屏幕的整个宽度(当没有可滚动内容时它会这样做)。但是,当内容超过浏览器窗口的 100% 时,它不会扩展到页面高度的 100%。 如果我设置 h
我正在尝试选择过去 5 天的整数字段的总和,我需要将它分组为每一天。 我在确定分组时遇到了一些问题。到目前为止,这是我的 sql 查询: select sum(`amount_sale`) a
我是一名优秀的程序员,十分优秀!