当前位置: 首页>>代码示例>>C#>>正文


C# DateTimeZoneHandling类代码示例

本文整理汇总了C#中DateTimeZoneHandling的典型用法代码示例。如果您正苦于以下问题:C# DateTimeZoneHandling类的具体用法?C# DateTimeZoneHandling怎么用?C# DateTimeZoneHandling使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DateTimeZoneHandling类属于命名空间,在下文中一共展示了DateTimeZoneHandling类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: JsonReader

 // Token: 0x06000073 RID: 115
 // RVA: 0x00006094 File Offset: 0x00004294
 protected JsonReader()
 {
     this._currentState = JsonReader.State.Start;
     this._stack = new List<JsonPosition>(4);
     this._dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
     this._dateParseHandling = DateParseHandling.DateTime;
     this._floatParseHandling = FloatParseHandling.Double;
     this.CloseInput = true;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:11,代码来源:JsonReader.cs

示例2: SerializeUsing

		private string SerializeUsing(Flight flight, DateTimeZoneHandling handling)
		{
			var settings = new ConnectionSettings()
				.SetDefaultPropertyNameInferrer(p=>p)
				.SetJsonSerializerSettingsModifier(s =>
				{
					s.DateFormatHandling = DateFormatHandling.IsoDateFormat;
					s.DateTimeZoneHandling = handling;
				});
			var client = new ElasticClient(settings);
			return client.Serializer.Serialize(flight).Utf8String();
		}
开发者ID:BiYiTuan,项目名称:elasticsearch-net,代码行数:12,代码来源:ConnectionSettingsTests.cs

示例3: EnsureDateTime

        internal static DateTime EnsureDateTime(DateTime value, DateTimeZoneHandling timeZone)
        {
            switch (timeZone)
            {
                case DateTimeZoneHandling.Local:
                    value = SwitchToLocalTime(value);
                    break;
                case DateTimeZoneHandling.Utc:
                    value = SwitchToUtcTime(value);
                    break;
                case DateTimeZoneHandling.Unspecified:
                    value = new DateTime(value.Ticks, DateTimeKind.Unspecified);
                    break;
                case DateTimeZoneHandling.RoundtripKind:
                    break;
                default:
                    throw new ArgumentException("Invalid date time handling value.");
            }

            return value;
        }
开发者ID:fszlin,项目名称:Newtonsoft.Json,代码行数:21,代码来源:DateTimeUtils.cs

示例4: JsonReader

        /// <summary>
        /// Initializes a new instance of the <see cref="JsonReader"/> class with the specified <see cref="TextReader"/>.
        /// </summary>
        protected JsonReader()
        {
            _currentState = State.Start;
            _dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
            _dateParseHandling = DateParseHandling.DateTime;
            _floatParseHandling = FloatParseHandling.Double;

            CloseInput = true;
        }
开发者ID:benerdin,项目名称:Newtonsoft.Json,代码行数:12,代码来源:JsonReader.cs

示例5: JsonReader

    /// <summary>
    /// Initializes a new instance of the <see cref="JsonReader"/> class with the specified <see cref="TextReader"/>.
    /// </summary>
    protected JsonReader()
    {
      _currentState = State.Start;
      _stack = new List<JsonPosition>(4);
      _dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
      _dateParseHandling = DateParseHandling.DateTime;
      _floatParseHandling = FloatParseHandling.PreferDecimalFallbackToDouble;

      CloseInput = true;
    }
开发者ID:cocytus,项目名称:ravendb,代码行数:13,代码来源:JsonReader.cs

示例6: TryParseDateTimeMicrosoft

        private static bool TryParseDateTimeMicrosoft(StringReference text, DateTimeZoneHandling dateTimeZoneHandling, out DateTime dt)
        {
            long ticks;
            TimeSpan offset;
            DateTimeKind kind;

            if (!TryParseMicrosoftDate(text, out ticks, out offset, out kind))
            {
                dt = default(DateTime);
                return false;
            }

            DateTime utcDateTime = ConvertJavaScriptTicksToDateTime(ticks);

            switch (kind)
            {
                case DateTimeKind.Unspecified:
                    dt = DateTime.SpecifyKind(utcDateTime.ToLocalTime(), DateTimeKind.Unspecified);
                    break;
                case DateTimeKind.Local:
                    dt = utcDateTime.ToLocalTime();
                    break;
                default:
                    dt = utcDateTime;
                    break;
            }

            dt = EnsureDateTime(dt, dateTimeZoneHandling);
            return true;
        }
开发者ID:fszlin,项目名称:Newtonsoft.Json,代码行数:30,代码来源:DateTimeUtils.cs

示例7: TryParseDateTime

        internal static bool TryParseDateTime(StringReference s, DateTimeZoneHandling dateTimeZoneHandling, string dateFormatString, CultureInfo culture, out DateTime dt)
        {
            if (s.Length > 0)
            {
                int i = s.StartIndex;
                if (s[i] == '/')
                {
                    if (s.Length >= 9 && s.StartsWith("/Date(") && s.EndsWith(")/"))
                    {
                        if (TryParseDateTimeMicrosoft(s, dateTimeZoneHandling, out dt))
                        {
                            return true;
                        }
                    }
                }
                else if (s.Length >= 19 && s.Length <= 40 && char.IsDigit(s[i]) && s[i + 10] == 'T')
                {
                    if (TryParseDateTimeIso(s, dateTimeZoneHandling, out dt))
                    {
                        return true;
                    }
                }

                if (!string.IsNullOrEmpty(dateFormatString))
                {
                    if (TryParseDateTimeExact(s.ToString(), dateTimeZoneHandling, dateFormatString, culture, out dt))
                    {
                        return true;
                    }
                }
            }

            dt = default(DateTime);
            return false;
        }
开发者ID:fszlin,项目名称:Newtonsoft.Json,代码行数:35,代码来源:DateTimeUtils.cs

示例8: TryParseDateMicrosoft

    private static bool TryParseDateMicrosoft(string text, DateParseHandling dateParseHandling, DateTimeZoneHandling dateTimeZoneHandling, out object dt)
    {
      string value = text.Substring(6, text.Length - 8);
      DateTimeKind kind = DateTimeKind.Utc;

      int index = value.IndexOf('+', 1);

      if (index == -1)
        index = value.IndexOf('-', 1);

      TimeSpan offset = TimeSpan.Zero;

      if (index != -1)
      {
        kind = DateTimeKind.Local;
        offset = ReadOffset(value.Substring(index));
        value = value.Substring(0, index);
      }

      long javaScriptTicks = long.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);

      DateTime utcDateTime = ConvertJavaScriptTicksToDateTime(javaScriptTicks);

#if !NET20
      if (dateParseHandling == DateParseHandling.DateTimeOffset)
      {
        dt = new DateTimeOffset(utcDateTime.Add(offset).Ticks, offset);
        return true;
      }
      else
#endif
      {
        DateTime dateTime;

        switch (kind)
        {
          case DateTimeKind.Unspecified:
            dateTime = DateTime.SpecifyKind(utcDateTime.ToLocalTime(), DateTimeKind.Unspecified);
            break;
          case DateTimeKind.Local:
            dateTime = utcDateTime.ToLocalTime();
            break;
          default:
            dateTime = utcDateTime;
            break;
        }

        dt = EnsureDateTime(dateTime, dateTimeZoneHandling);
        return true;
      }
    }
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:51,代码来源:DateTimeUtils.cs

示例9: JsonWriter

        /// <summary>
        /// Creates an instance of the <c>JsonWriter</c> class. 
        /// </summary>
        protected JsonWriter()
        {
            _currentState = State.Start;
            _formatting = Formatting.None;
            _dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;

            CloseOutput = true;
        }
开发者ID:cilliemalan,项目名称:Cargo,代码行数:11,代码来源:JsonWriter.cs

示例10: TryParseDateMicrosoft

        private static bool TryParseDateMicrosoft(string text, DateParseHandling dateParseHandling, DateTimeZoneHandling dateTimeZoneHandling, out object dt)
        {
            string value = text.Substring(6, text.Length - 8);
            DateTimeKind kind = DateTimeKind.Utc;

            int index = value.IndexOf('+', 1);

            if (index == -1)
                index = value.IndexOf('-', 1);

            if (index != -1)
            {
                kind = DateTimeKind.Local;

                value = value.Substring(0, index);
            }

            long javaScriptTicks;
            if (!long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out javaScriptTicks))
            {
                dt = null;
                return false;
            }

            DateTime utcDateTime = ConvertJavaScriptTicksToDateTime(javaScriptTicks);

            DateTime dateTime;
            switch (kind)
            {
                case DateTimeKind.Unspecified:
                    dateTime = DateTime.SpecifyKind(utcDateTime.ToLocalTime(), DateTimeKind.Unspecified);
                    break;
                case DateTimeKind.Local:
                    dateTime = utcDateTime.ToLocalTime();
                    break;
                default:
                    dateTime = utcDateTime;
                    break;
            }

            dt = EnsureDateTime(dateTime, dateTimeZoneHandling);
            return true;
        }
开发者ID:Bluesubstance,项目名称:Unity3d_Login_Example_Project,代码行数:43,代码来源:DateTimeUtils.cs

示例11: ConvertDateTime

 public static DateTime ConvertDateTime(double epoch_time, string timezone, DateTimeZoneHandling tzHandle)
 {
     var dto = ConvertDateTimeOffset(epoch_time, timezone);
     switch (tzHandle)
     {
         case DateTimeZoneHandling.Local:
             return dto.LocalDateTime;
         case DateTimeZoneHandling.Utc:
             return dto.UtcDateTime;
         case DateTimeZoneHandling.Unspecified:
             return dto.DateTime;
         case DateTimeZoneHandling.RoundtripKind:
             return dto.Offset == TimeSpan.Zero ? dto.UtcDateTime : dto.LocalDateTime;
         default:
             throw new JsonSerializationException("Invalid date time handling value.");
     }
 }
开发者ID:fjsnogueira,项目名称:RethinkDb.Driver,代码行数:17,代码来源:ReqlDateTimeConverter.cs

示例12: TryParseDateMicrosoft

 // Token: 0x06000D21 RID: 3361
 // RVA: 0x0004A63C File Offset: 0x0004883C
 private static bool TryParseDateMicrosoft(string text, DateParseHandling dateParseHandling, DateTimeZoneHandling dateTimeZoneHandling, out object dt)
 {
     string text2 = text.Substring(6, text.Length - 8);
     DateTimeKind dateTimeKind = DateTimeKind.Utc;
     int num = text2.IndexOf('+', 1);
     if (num == -1)
     {
         num = text2.IndexOf('-', 1);
     }
     if (num != -1)
     {
         dateTimeKind = DateTimeKind.Local;
         text2 = text2.Substring(0, num);
     }
     long javaScriptTicks;
     if (!long.TryParse(text2, NumberStyles.Integer, CultureInfo.InvariantCulture, out javaScriptTicks))
     {
         dt = null;
         return false;
     }
     DateTime dateTime = DateTimeUtils.ConvertJavaScriptTicksToDateTime(javaScriptTicks);
     DateTime value;
     switch (dateTimeKind)
     {
     case DateTimeKind.Unspecified:
         value = DateTime.SpecifyKind(dateTime.ToLocalTime(), DateTimeKind.Unspecified);
         goto IL_8E;
     case DateTimeKind.Local:
         value = dateTime.ToLocalTime();
         goto IL_8E;
     }
     value = dateTime;
     IL_8E:
     dt = DateTimeUtils.EnsureDateTime(value, dateTimeZoneHandling);
     return true;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:38,代码来源:DateTimeUtils.cs

示例13: TryParseDateExact

 // Token: 0x06000D22 RID: 3362
 // RVA: 0x0004A6E8 File Offset: 0x000488E8
 private static bool TryParseDateExact(string text, DateParseHandling dateParseHandling, DateTimeZoneHandling dateTimeZoneHandling, string dateFormatString, CultureInfo culture, out object dt)
 {
     DateTime dateTime;
     if (DateTime.TryParseExact(text, dateFormatString, culture, DateTimeStyles.RoundtripKind, out dateTime))
     {
         dateTime = DateTimeUtils.EnsureDateTime(dateTime, dateTimeZoneHandling);
         dt = dateTime;
         return true;
     }
     dt = null;
     return false;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:14,代码来源:DateTimeUtils.cs

示例14: TryParseDateIso

 // Token: 0x06000D1F RID: 3359
 // RVA: 0x0004A3D4 File Offset: 0x000485D4
 internal static bool TryParseDateIso(string text, DateParseHandling dateParseHandling, DateTimeZoneHandling dateTimeZoneHandling, out object dt)
 {
     DateTimeParser dateTimeParser = default(DateTimeParser);
     if (!dateTimeParser.Parse(text))
     {
         dt = null;
         return false;
     }
     DateTime dateTime = new DateTime(dateTimeParser.Year, dateTimeParser.Month, dateTimeParser.Day, dateTimeParser.Hour, dateTimeParser.Minute, dateTimeParser.Second);
     dateTime = dateTime.AddTicks((long)dateTimeParser.Fraction);
     switch (dateTimeParser.Zone)
     {
     case ParserTimeZone.Utc:
         dateTime = new DateTime(dateTime.Ticks, DateTimeKind.Utc);
         break;
     case ParserTimeZone.LocalWestOfUtc:
     {
         TimeSpan timeSpan = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0);
         long num = dateTime.Ticks + timeSpan.Ticks;
         if (num <= DateTime.MaxValue.Ticks)
         {
             dateTime = new DateTime(num, DateTimeKind.Utc).ToLocalTime();
         }
         else
         {
             num += DateTimeUtils.GetUtcOffset(dateTime).Ticks;
             if (num > DateTime.MaxValue.Ticks)
             {
                 num = DateTime.MaxValue.Ticks;
             }
             dateTime = new DateTime(num, DateTimeKind.Local);
         }
         break;
     }
     case ParserTimeZone.LocalEastOfUtc:
     {
         TimeSpan timeSpan2 = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0);
         long num = dateTime.Ticks - timeSpan2.Ticks;
         if (num >= DateTime.MinValue.Ticks)
         {
             dateTime = new DateTime(num, DateTimeKind.Utc).ToLocalTime();
         }
         else
         {
             num += DateTimeUtils.GetUtcOffset(dateTime).Ticks;
             if (num < DateTime.MinValue.Ticks)
             {
                 num = DateTime.MinValue.Ticks;
             }
             dateTime = new DateTime(num, DateTimeKind.Local);
         }
         break;
     }
     }
     dt = DateTimeUtils.EnsureDateTime(dateTime, dateTimeZoneHandling);
     return true;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:59,代码来源:DateTimeUtils.cs

示例15: TryParseDateIso

    internal static bool TryParseDateIso(string text, DateParseHandling dateParseHandling, DateTimeZoneHandling dateTimeZoneHandling, out object dt)
    {
      DateTimeParser dateTimeParser = new DateTimeParser();
      if (!dateTimeParser.Parse(text))
      {
        dt = null;
        return false;
      }

      DateTime d = new DateTime(dateTimeParser.Year, dateTimeParser.Month, dateTimeParser.Day, dateTimeParser.Hour, dateTimeParser.Minute, dateTimeParser.Second);
      d = d.AddTicks(dateTimeParser.Fraction);

#if !NET20
      if (dateParseHandling == DateParseHandling.DateTimeOffset)
      {
        TimeSpan offset;

        switch (dateTimeParser.Zone)
        {
          case ParserTimeZone.Utc:
            offset = new TimeSpan(0L);
            break;
          case ParserTimeZone.LocalWestOfUtc:
            offset = new TimeSpan(-dateTimeParser.ZoneHour, -dateTimeParser.ZoneMinute, 0);
            break;
          case ParserTimeZone.LocalEastOfUtc:
            offset = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0);
            break;
          default:
            offset = TimeZoneInfo.Local.GetUtcOffset(d);
            break;
        }

        long ticks = d.Ticks - offset.Ticks;
        if (ticks < 0 || ticks > 3155378975999999999)
        {
          dt = null;
          return false;
        }

        dt = new DateTimeOffset(d, offset);
        return true;
      }
      else
#endif
      {
        long ticks;

        switch (dateTimeParser.Zone)
        {
          case ParserTimeZone.Utc:
            d = new DateTime(d.Ticks, DateTimeKind.Utc);
            break;

          case ParserTimeZone.LocalWestOfUtc:
            {
              TimeSpan offset = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0);
              ticks = d.Ticks + offset.Ticks;
              if (ticks <= DateTime.MaxValue.Ticks)
              {
                d = new DateTime(ticks, DateTimeKind.Utc).ToLocalTime();
              }
              else
              {
                ticks += d.GetUtcOffset().Ticks;
                if (ticks > DateTime.MaxValue.Ticks)
                  ticks = DateTime.MaxValue.Ticks;

                d = new DateTime(ticks, DateTimeKind.Local);
              }
              break;
            }
          case ParserTimeZone.LocalEastOfUtc:
            {
              TimeSpan offset = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0);
              ticks = d.Ticks - offset.Ticks;
              if (ticks >= DateTime.MinValue.Ticks)
              {
                d = new DateTime(ticks, DateTimeKind.Utc).ToLocalTime();
              }
              else
              {
                ticks += d.GetUtcOffset().Ticks;
                if (ticks < DateTime.MinValue.Ticks)
                  ticks = DateTime.MinValue.Ticks;

                d = new DateTime(ticks, DateTimeKind.Local);
              }
              break;
            }
        }

        dt = EnsureDateTime(d, dateTimeZoneHandling);
        return true;
      }
    }
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:96,代码来源:DateTimeUtils.cs


注:本文中的DateTimeZoneHandling类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。