sql - 检索时区和日期时间的夏令时
问题描述
我想要 SQL Server 中通过日期和时区的 Daylight。
例如,我正在传递 TimeZone = 'PST' AND Date = '2020-05-20 09:41:55.130'。
我需要日光将当前日期申请到 pst 时区输出“是”或“否”。
注意:时区和日期是动态的。
我有 C# 代码,它工作正常。
public static bool IsDaylightSavingTime(string timeZone)
{
try
{
//if isDaylight is true in 'PST' then offset is -7 else -8
bool isDaylight = false;
DateTime localTime = DateTime.Now;
DateTime UTCTime = DateTime.UtcNow;
string TimeZoneFullName = string.Empty;
if (timeZone.ToUpper() == "PST" || timeZone.ToUpper() == "PT")
{
TimeZoneFullName = "Pacific Standard Time"; //UTC−08 DST −07:00
}
else if (timeZone.ToUpper() == "MST" || timeZone.ToUpper() == "MT")
{
TimeZoneFullName = "Mountain Standard Time"; //UTC−07 DST −06:00
}
else if (timeZone.ToUpper() == "CST" || timeZone.ToUpper() == "CT")
{
TimeZoneFullName = "Central Standard Time"; //UTC−06 DST −05:00
}
else if (timeZone.ToUpper() == "EST" || timeZone.ToUpper() == "ET")
{
TimeZoneFullName = "Eastern Standard Time"; //UTC−05 DST −04:00
}
if (TimeZoneFullName != string.Empty)
{
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneFullName);
isDaylight = tzi.IsDaylightSavingTime(localTime);
}
//WriteLog(string.Format("{0} isDaylight : {1} ", timeZone, isDaylight));
return isDaylight;
}
catch (Exception ex)
{
WriteLog(string.Format("Error while check Day light Saving Time. (Utility - IsDaylightSavingTime) \n TimeZone {0} \n Error : {1}", timeZone, ex.ToString()));
return false;
}
}
解决方案
推荐阅读
- javascript - innerWidth 和屏幕宽度显示相同的值?
- c++ - 当堆栈为空时,在(模板化的)堆栈弹出方法中要做什么?
- python - 如何使用 requests 和 beautifulsoup 打印网站中的课程内容
- r - 从零开始的多元回归错误
- c - “分段错误”可能是由 C 中的内存分配发出的
- javascript - 在滑块中使用 img src 原型来更改滑块图像
- selenium - Selenium 和 Chromedriver - 无法点击元素
- c# - 为 asp.net core 2.02 配置 Nlog
- c++ - 基于整数向量执行位排列的有效方法?
- arrays - 将 Javascript 类型定义为来自另一个 Object 属性值的文字数组