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


C# DateParseHandling类代码示例

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


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

示例3: TryParseDateTime

    internal static bool TryParseDateTime(string s, DateParseHandling dateParseHandling, DateTimeZoneHandling dateTimeZoneHandling, out object dt)
    {
      if (s.Length > 0)
      {
        if (s[0] == '/')
        {
          if (s.StartsWith("/Date(", StringComparison.Ordinal) && s.EndsWith(")/", StringComparison.Ordinal))
          {
            return TryParseDateMicrosoft(s, dateParseHandling, dateTimeZoneHandling, out dt);
          }
        }
        else if (s.Length >= 19 && s.Length <= 40 && char.IsDigit(s[0]) && s[10] == 'T')
        {
          return TryParseDateIso(s, dateParseHandling, dateTimeZoneHandling, out dt);
        }
      }

      dt = null;
      return false;
    }
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:20,代码来源:DateTimeUtils.cs

示例4: 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

示例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;
            _dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
            _dateParseHandling = DateParseHandling.DateTime;
            _floatParseHandling = FloatParseHandling.Double;

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

示例6: 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

示例7: TryParseDateExact

        private static bool TryParseDateExact(string text, DateParseHandling dateParseHandling, DateTimeZoneHandling dateTimeZoneHandling, string dateFormatString, CultureInfo culture, out object dt)
        {
            #if !NET20
            if (dateParseHandling == DateParseHandling.DateTimeOffset)
            {
                DateTimeOffset temp;
                if (DateTimeOffset.TryParseExact(text, dateFormatString, culture, DateTimeStyles.RoundtripKind, out temp))
                {
                    dt = temp;
                    return true;
                }
            }
            else
            #endif
            {
                DateTime temp;
                if (DateTime.TryParseExact(text, dateFormatString, culture, DateTimeStyles.RoundtripKind, out temp))
                {
                    temp = EnsureDateTime(temp, dateTimeZoneHandling);
                    dt = temp;
                    return true;
                }
            }

            dt = null;
            return false;
        }
开发者ID:mikeqian,项目名称:donetcommon,代码行数:27,代码来源:DateTimeUtils.cs

示例8: TryParseDateTime

        internal static bool TryParseDateTime(string s, DateParseHandling dateParseHandling, DateTimeZoneHandling dateTimeZoneHandling, string dateFormatString, CultureInfo culture, out object dt)
        {
            if (s.Length > 0)
            {
                if (s[0] == '/')
                {
                    if (s.StartsWith("/Date(", StringComparison.Ordinal) && s.EndsWith(")/", StringComparison.Ordinal))
                    {
                        if (TryParseDateMicrosoft(s, dateParseHandling, dateTimeZoneHandling, out dt))
                            return true;
                    }
                }
                else if (s.Length >= 19 && s.Length <= 40 && char.IsDigit(s[0]) && s[10] == 'T')
                {
                    if (TryParseDateIso(s, dateParseHandling, dateTimeZoneHandling, out dt))
                        return true;
                }

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

            dt = null;
            return false;
        }
开发者ID:mikeqian,项目名称:donetcommon,代码行数:28,代码来源:DateTimeUtils.cs

示例9: 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;

      CloseInput = true;
    }
开发者ID:leesanghyun2,项目名称:mp-onlinevideos2,代码行数:12,代码来源:JsonReader.cs

示例10: TryParseDateIso

        internal static bool TryParseDateIso(string text, DateParseHandling dateParseHandling, DateTimeZoneHandling dateTimeZoneHandling, out object dt)
        {
            const string isoDateFormat = "yyyy-MM-ddTHH:mm:ss.FFFFFFFK";

#if !NET20
            if (dateParseHandling == DateParseHandling.DateTimeOffset)
            {
                DateTimeOffset dateTimeOffset;
                if (DateTimeOffset.TryParseExact(text, isoDateFormat, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dateTimeOffset))
                {
                    dt = dateTimeOffset;
                    return true;
                }
            }
            else
#endif
            {
                DateTime dateTime;
                if (DateTime.TryParseExact(text, isoDateFormat, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dateTime))
                {
                    dateTime = DateTimeUtils.EnsureDateTime(dateTime, dateTimeZoneHandling);

                    dt = dateTime;
                    return true;
                }
            }

            dt = null;
            return false;
        }
开发者ID:JamesNK,项目名称:Newtonsoft.Json,代码行数:30,代码来源:DateTimeUtilsTests.cs

示例11: 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

示例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


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