本文整理汇总了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);
}
示例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();
}
示例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));
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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));
}