代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
美国东部时间和北京时间之间的转换
作者:
玉开
/ 发布于
2011/5/31
/
678
<div> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// <summary> </font></td> </tr> </tbody> </table> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// AMESTime 的摘要说明: </font></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// 美东时间的转换 </font></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// </font></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// 美东时间在UTC-5时区,美国有夏时制,即在夏令时启用之后美东时间比起所在时区早一个小时,即UTC-4 </font></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// 在未使用夏令时时美东时间比北京时间(UTC+8时区)晚13个小时,在启用夏令时时美东时间比北京时间晚12个小时 </font></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// </font></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// </font></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// 美国国会2005年通过的能源法案,夏令时时段:从2007年开始每年3月的第二个星期日开始夏令时,结束日期为11月的第一个星期日。 </font></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// </summary> </font></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">public</font></strong> "csharp keyword"><strong><font color="#006699">class</font></strong> "csharp plain">AMESTime </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">private</font></strong> "csharp keyword"><strong><font color="#006699">static</font></strong> "csharp plain">DateTime _thisYearDaylightSavingTimeStart, </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">_thisYearDaylightSavingTimeEnd; </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content"></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">private</font></strong> "csharp keyword"><strong><font color="#006699">const</font></strong> "csharp keyword"><strong><font color="#006699">int</font></strong> "csharp plain">TIMEZONE_OFFSET_DAY_SAVING_LIGHT = -12; </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">private</font></strong> "csharp keyword"><strong><font color="#006699">const</font></strong> "csharp keyword"><strong><font color="#006699">int</font></strong> "csharp plain">TIMEZONE_OFFSET = -13; </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content"></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">public</font></strong> "csharp keyword"><strong><font color="#006699">static</font></strong> "csharp plain">DateTime BeijingTimeToAMESTime(DateTime beijingTime) </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">int</font></strong> "csharp plain">offsetHours = (IsNowAMESDayLightSavingTime ? TIMEZONE_OFFSET_DAY_SAVING_LIGHT:TIMEZONE_OFFSET); </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content"></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">return</font></strong> "csharp plain">beijingTime.AddHours(offsetHours); </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content"></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">public</font></strong> "csharp keyword"><strong><font color="#006699">static</font></strong> "csharp plain">DateTime AMESNow </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">get</font></strong></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">return</font></strong> "csharp plain">BeijingTimeToAMESTime(DateTime.Now); </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content"></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// <summary> </font></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// 判断当前日期是否是美国夏令时 </font></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// 从2007年开始每年3月的第二个星期日开始夏令时,结束日期为11月的第一个星期日。 </font></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// </summary> </font></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// <returns>是,返回true,否则为false</returns> </font></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">public</font></strong> "csharp keyword"><strong><font color="#006699">static</font></strong> "csharp keyword"><strong><font color="#006699">bool</font></strong> "csharp plain">IsNowAMESDayLightSavingTime </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">get</font></strong></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">return</font></strong> "csharp plain">DateTime.UtcNow > DayLightSavingStartTimeUtc </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">&& DateTime.UtcNow < DayLightSavingEndTimeUtc; </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content"></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// <summary> </font></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// 夏令时开始时间 </font></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// </summary> </font></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">static</font></strong> "csharp plain">DateTime DayLightSavingStartTimeUtc </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">get</font></strong></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">if</font></strong>"csharp plain">(_thisYearDaylightSavingTimeStart.Year != DateTime.Now.Year) </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">DateTime temp = "csharp keyword"><strong><font color="#006699">new</font></strong> "csharp plain">DateTime(DateTime.Now.Year,3,8,0,0,0); </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">while</font></strong>"csharp plain">(temp.DayOfWeek != DayOfWeek.Sunday) </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">temp = temp.AddDays(1); </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">_thisYearDaylightSavingTimeStart = temp.AddHours(TIMEZONE_OFFSET); </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content"></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">return</font></strong> "csharp plain">_thisYearDaylightSavingTimeStart; </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content"></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// <summary> </font></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// 夏令时结束时间 </font></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp color1"><font color="#808080">/// </summary> </font></td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">static</font></strong> "csharp plain">DateTime DayLightSavingEndTimeUtc </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">get</font></strong></td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">if</font></strong>"csharp plain">(_thisYearDaylightSavingTimeEnd.Year != DateTime.Now.Year) </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">DateTime temp = "csharp keyword"><strong><font color="#006699">new</font></strong> "csharp plain">DateTime(DateTime.Now.Year,11,1,0,0,0); </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">while</font></strong>"csharp plain">(temp.DayOfWeek != DayOfWeek.Sunday) </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">{ </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">temp = temp.AddDays(1); </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">_thisYearDaylightSavingTimeEnd = temp.AddHours(TIMEZONE_OFFSET_DAY_SAVING_LIGHT); </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp keyword"><strong><font color="#006699">return</font></strong> "csharp plain">_thisYearDaylightSavingTimeEnd; </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt1"> <table> <tbody> <tr> <td class="content">"csharp plain">} </td> </tr> </tbody> </table> </div> <div class="line alt2"> <table> <tbody> <tr> <td class="content">"csharp plain">}</td> </tr> </tbody> </table> </div> </div>
试试其它关键字
时间转换
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
玉开
贡献的其它代码
(
2
)
.
C#按关闭按钮实现最小化,按ESC才关闭的实现
.
美国东部时间和北京时间之间的转换
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3