Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 时区信息到时区信息结构_C#_Timezone - Fatal编程技术网

C# 时区信息到时区信息结构

C# 时区信息到时区信息结构,c#,timezone,C#,Timezone,嘿,我有一个对象,我想从这个对象创建一个结构 Bias、StandardDate和Daylightdate很容易获得。然而,我在获取标准偏差和daylightbias时遇到了问题。所以问题是,如何从TimeZOneInfo对象获得standardbias,以及如何获得daylightbias的相同结果(有一个AdjustmentRule.DaylightDelta,但正如您所看到的,我需要的是偏移量而不是delta) 谢谢。时区信息帮助非常有用。它说大多数时区的标准偏差为0。对我来说,标准偏差不

嘿,我有一个对象,我想从这个对象创建一个结构

Bias、StandardDate和Daylightdate很容易获得。然而,我在获取标准偏差和daylightbias时遇到了问题。所以问题是,如何从TimeZOneInfo对象获得standardbias,以及如何获得daylightbias的相同结果(有一个AdjustmentRule.DaylightDelta,但正如您所看到的,我需要的是偏移量而不是delta)


谢谢。

时区信息帮助非常有用。它说大多数时区的标准偏差为0。对我来说,标准偏差不为零的时区没有多大意义。这不是“标准”的意思吗

DaylightDelta是标准UTC偏移和日光UTC偏移之间的差值。DaylightBias的定义相同,因此DaylightDelta就是DaylightBias


我现在无法破解这个问题,但我建议你在你的时区里玩数据游戏。或者,是否有一种方法可以使用Win32对象来获取相应时区信息的时区信息结构,而不是创建对象?类似于在DYNAMIC\u TIME\u ZONE\u INFORMATION.StandardName?中指定TimeZoneInfo.StandardName,我将此代码与使用CrankedUp(读取时区信息)的结果进行了比较,结果在我的Windows XP sp3机器上是相同的。您的结果可能会有所不同

TimeZoneInfo.AdjustmentRule[] adjustmentRules = timeZoneInfo.GetAdjustmentRules();
TimeZoneInfo.AdjustmentRule adjustmentRule = null;
if (adjustmentRules.Length > 0)
{
    // Find the single record that encompasses today's date. If none exists, sets adjustmentRule to null.
    adjustmentRule = adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd);
}

double bias = -timeZoneInfo.BaseUtcOffset.TotalMinutes; // I'm not sure why this number needs to be negated, but it does.
string daylightName = timeZoneInfo.DaylightName;
string standardName = timeZoneInfo.StandardName;
double daylightBias = adjustmentRule == null ? -60 : -adjustmentRule.DaylightDelta.TotalMinutes; // Not sure why default is -60, or why this number needs to be negated, but it does.
int daylightDay = 0;
int daylightDayOfWeek = 0;
int daylightHour = 0;
int daylightMonth = 0;
int standardDay = 0;
int standardDayOfWeek = 0;
int standardHour = 0;
int standardMonth = 0;

if (adjustmentRule != null)
{
    TimeZoneInfo.TransitionTime daylightTime = adjustmentRule.DaylightTransitionStart;
    TimeZoneInfo.TransitionTime standardTime = adjustmentRule.DaylightTransitionEnd;

    // Valid values depend on IsFixedDateRule: http://msdn.microsoft.com/en-us/library/system.timezoneinfo.transitiontime.isfixeddaterule.
    daylightDay = daylightTime.IsFixedDateRule ? daylightTime.Day : daylightTime.Week;
    daylightDayOfWeek = daylightTime.IsFixedDateRule ? -1 : (int)daylightTime.DayOfWeek;
    daylightHour = daylightTime.TimeOfDay.Hour;
    daylightMonth = daylightTime.Month;

    standardDay = standardTime.IsFixedDateRule ? standardTime.Day : standardTime.Week;
    standardDayOfWeek = standardTime.IsFixedDateRule ? -1 : (int)standardTime.DayOfWeek;
    standardHour = standardTime.TimeOfDay.Hour;
    standardMonth = standardTime.Month;
}
TimeZoneInfo.AdjustmentRule[]adjustmentRules=TimeZoneInfo.GetAdjustmentRules();
TimeZoneInfo.AdjustmentRule AdjustmentRule=null;
如果(adjustmentRules.Length>0)
{
//查找包含今天日期的单个记录。如果不存在,则将adjustmentRule设置为null。

adjustmentRule=adjustmentRules.SingleOrDefault(ar=>ar.DateStart)如何获取标准偏差?