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


C# DateFormatHandling类代码示例

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


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

示例1: GetOffset

        protected string GetOffset(DateTime d, DateFormatHandling dateFormatHandling)
        {
            char[] chars = new char[8];
            int pos = DateTimeUtils.WriteDateTimeOffset(chars, 0, DateTime.SpecifyKind(d, DateTimeKind.Local).GetUtcOffset(), dateFormatHandling);

            return new string(chars, 0, pos);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:7,代码来源:TestFixtureBase.cs

示例2: GetOffset

    protected string GetOffset(DateTime d, DateFormatHandling dateFormatHandling)
    {
      StringWriter sw = new StringWriter();
      JsonConvert.WriteDateTimeOffset(sw, DateTime.SpecifyKind(d, DateTimeKind.Local).GetUtcOffset(), dateFormatHandling);
      sw.Flush();

      return sw.ToString();
    }
开发者ID:handcraftsman,项目名称:Newtonsoft.Json,代码行数:8,代码来源:TestFixtureBase.cs

示例3: WriteDateTimeOffsetString

        internal static void WriteDateTimeOffsetString(TextWriter writer, DateTimeOffset value, DateFormatHandling format, string formatString, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(formatString))
            {
                char[] chars = new char[64];
                int pos = WriteDateTimeString(chars, 0, (format == DateFormatHandling.IsoDateFormat) ? value.DateTime : value.UtcDateTime, value.Offset, DateTimeKind.Local, format);

                writer.Write(chars, 0, pos);
            }
            else
            {
                writer.Write(value.ToString(formatString, culture));
            }
        }
开发者ID:fszlin,项目名称:Newtonsoft.Json,代码行数:14,代码来源:DateTimeUtils.cs

示例4: WriteDateTimeOffset

        internal static int WriteDateTimeOffset(char[] chars, int start, TimeSpan offset, DateFormatHandling format)
        {
            chars[start++] = (offset.Ticks >= 0L) ? '+' : '-';

            int absHours = Math.Abs(offset.Hours);
            CopyIntToCharArray(chars, start, absHours, 2);
            start += 2;

            if (format == DateFormatHandling.IsoDateFormat)
            {
                chars[start++] = ':';
            }

            int absMinutes = Math.Abs(offset.Minutes);
            CopyIntToCharArray(chars, start, absMinutes, 2);
            start += 2;

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

示例5: WriteDateTimeString

        internal static int WriteDateTimeString(char[] chars, int start, DateTime value, TimeSpan? offset, DateTimeKind kind, DateFormatHandling format)
        {
            int pos = start;

            if (format == DateFormatHandling.MicrosoftDateFormat)
            {
                TimeSpan o = offset ?? value.GetUtcOffset();

                long javaScriptTicks = ConvertDateTimeToJavaScriptTicks(value, o);

                @"\/Date(".CopyTo(0, chars, pos, 7);
                pos += 7;

                string ticksText = javaScriptTicks.ToString(CultureInfo.InvariantCulture);
                ticksText.CopyTo(0, chars, pos, ticksText.Length);
                pos += ticksText.Length;

                switch (kind)
                {
                    case DateTimeKind.Unspecified:
                        if (value != DateTime.MaxValue && value != DateTime.MinValue)
                        {
                            pos = WriteDateTimeOffset(chars, pos, o, format);
                        }
                        break;
                    case DateTimeKind.Local:
                        pos = WriteDateTimeOffset(chars, pos, o, format);
                        break;
                }

                @")\/".CopyTo(0, chars, pos, 3);
                pos += 3;
            }
            else
            {
                pos = WriteDefaultIsoDate(chars, pos, value);

                switch (kind)
                {
                    case DateTimeKind.Local:
                        pos = WriteDateTimeOffset(chars, pos, offset ?? value.GetUtcOffset(), format);
                        break;
                    case DateTimeKind.Utc:
                        chars[pos++] = 'Z';
                        break;
                }
            }

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

示例6: ToString

 /// <summary>
 /// Converts the <see cref="DateTimeOffset"/> to its JSON string representation using the <see cref="DateFormatHandling"/> specified.
 /// </summary>
 /// <param name="value">The value to convert.</param>
 /// <param name="format">The format the date will be converted to.</param>
 /// <returns>A JSON string representation of the <see cref="DateTimeOffset"/>.</returns>
 public static string ToString(DateTimeOffset value, DateFormatHandling format)
 {
   using (StringWriter writer = StringUtils.CreateStringWriter(64))
   {
     writer.Write('"');
     DateTimeUtils.WriteDateTimeOffsetString(writer, value, format, null, CultureInfo.InvariantCulture);
     writer.Write('"');
     return writer.ToString();
   }
 }
开发者ID:Teplitsa,项目名称:bezpregrad,代码行数:16,代码来源:JsonConvert.cs

示例7: WriteDateTimeString

 // Token: 0x06000D24 RID: 3364
 // RVA: 0x0004A774 File Offset: 0x00048974
 internal static int WriteDateTimeString(char[] chars, int start, DateTime value, TimeSpan? offset, DateTimeKind kind, DateFormatHandling format)
 {
     int num2;
     if (format == DateFormatHandling.MicrosoftDateFormat)
     {
         TimeSpan offset2 = offset ?? DateTimeUtils.GetUtcOffset(value);
         long num = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(value, offset2);
         "\\/Date(".CopyTo(0, chars, start, 7);
         num2 = start + 7;
         string text = num.ToString(CultureInfo.InvariantCulture);
         text.CopyTo(0, chars, num2, text.Length);
         num2 += text.Length;
         switch (kind)
         {
         case DateTimeKind.Unspecified:
             if (value != DateTime.MaxValue && value != DateTime.MinValue)
             {
                 num2 = DateTimeUtils.WriteDateTimeOffset(chars, num2, offset2, format);
             }
             break;
         case DateTimeKind.Local:
             num2 = DateTimeUtils.WriteDateTimeOffset(chars, num2, offset2, format);
             break;
         }
         ")\\/".CopyTo(0, chars, num2, 3);
         num2 += 3;
     }
     else
     {
         num2 = DateTimeUtils.WriteDefaultIsoDate(chars, start, value);
         switch (kind)
         {
         case DateTimeKind.Utc:
             chars[num2++] = 'Z';
             break;
         case DateTimeKind.Local:
             num2 = DateTimeUtils.WriteDateTimeOffset(chars, num2, offset ?? DateTimeUtils.GetUtcOffset(value), format);
             break;
         }
     }
     return num2;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:44,代码来源:DateTimeUtils.cs

示例8: WriteDateTimeOffset

 // Token: 0x06000D27 RID: 3367
 // RVA: 0x0004A980 File Offset: 0x00048B80
 internal static int WriteDateTimeOffset(char[] chars, int start, TimeSpan offset, DateFormatHandling format)
 {
     chars[start++] = ((offset.Ticks >= 0L) ? '+' : '-');
     int value = Math.Abs(offset.Hours);
     DateTimeUtils.CopyIntToCharArray(chars, start, value, 2);
     start += 2;
     if (format == DateFormatHandling.IsoDateFormat)
     {
         chars[start++] = ':';
     }
     int value2 = Math.Abs(offset.Minutes);
     DateTimeUtils.CopyIntToCharArray(chars, start, value2, 2);
     start += 2;
     return start;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:17,代码来源:DateTimeUtils.cs

示例9: WriteDateTimeOffsetString

 public static void WriteDateTimeOffsetString(TextWriter writer, DateTimeOffset value, DateFormatHandling format, string formatString, CultureInfo culture)
 {
     if (string.IsNullOrEmpty(formatString))
     {
         char[] array = new char[64];
         int count = DateTimeUtils.WriteDateTimeString(array, 0, (format == DateFormatHandling.IsoDateFormat) ? value.DateTime : value.UtcDateTime, new TimeSpan?(value.Offset), DateTimeKind.Local, format);
         writer.Write(array, 0, count);
         return;
     }
     writer.Write(value.ToString(formatString, culture));
 }
开发者ID:Halcyon-lang,项目名称:Halcyon-lang,代码行数:11,代码来源:DateTimeUtils.cs


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