我希望在sql server中为经过的日期和时区指定日光。
例如,我正在传递时区='pst'和日期='2020-05-20 09:41:55.130'。
我需要daylight正在申请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;
}
}
暂无答案!
目前还没有任何答案,快来回答吧!