本文整理汇总了C#中System.DateTime.ToStableUniversalTime方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.ToStableUniversalTime方法的具体用法?C# DateTime.ToStableUniversalTime怎么用?C# DateTime.ToStableUniversalTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.ToStableUniversalTime方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToShortestXsdDateTimeString
public static string ToShortestXsdDateTimeString(DateTime dateTime)
{
var timeOfDay = dateTime.TimeOfDay;
if (timeOfDay.Ticks == 0)
return dateTime.ToString(ShortDateTimeFormat);
if (timeOfDay.Milliseconds == 0)
return dateTime.ToStableUniversalTime().ToString(XsdDateTimeFormatSeconds);
return ToXsdDateTimeString(dateTime);
}
示例2: ToShortestXsdDateTimeString_works
public void ToShortestXsdDateTimeString_works()
{
var shortDate = new DateTime(1979, 5, 9);
const string shortDateString = "1979-05-09";
var shortDateTime = new DateTime(1979, 5, 9, 0, 0, 1, DateTimeKind.Utc);
var shortDateTimeString = shortDateTime.Equals(shortDateTime.ToStableUniversalTime())
? "1979-05-09T00:00:01Z"
: "1979-05-08T23:00:01Z";
var longDateTime = new DateTime(1979, 5, 9, 0, 0, 0, 1, DateTimeKind.Utc);
var longDateTimeString = longDateTime.Equals(longDateTime.ToStableUniversalTime())
? "1979-05-09T00:00:00.001Z"
: "1979-05-08T23:00:00.001Z";
Assert.That(shortDateString, Is.EqualTo(DateTimeSerializer.ToShortestXsdDateTimeString(shortDate)));
Assert.That(shortDateTimeString, Is.EqualTo(DateTimeSerializer.ToShortestXsdDateTimeString(shortDateTime)));
Assert.That(longDateTimeString, Is.EqualTo(DateTimeSerializer.ToShortestXsdDateTimeString(longDateTime)));
}
示例3: ToXsdDateTimeString
public static string ToXsdDateTimeString(DateTime dateTime)
{
return XmlConvert.ToString(dateTime.ToStableUniversalTime(), XmlDateTimeSerializationMode.Utc);
}
示例4: ToDateTimeString
public static string ToDateTimeString(DateTime dateTime)
{
return dateTime.ToStableUniversalTime().ToString(XsdDateTimeFormat);
}
示例5: ToXsdDateTimeString
public static string ToXsdDateTimeString(DateTime dateTime)
{
#if NETFX_CORE
return XmlConvert.ToString(dateTime.ToStableUniversalTime(), XsdDateTimeFormat);
#else
return XmlConvert.ToString(dateTime.ToStableUniversalTime(), XmlDateTimeSerializationMode.Utc);
#endif
}
示例6: AssertDatesAreEqual
private void AssertDatesAreEqual(DateTime toDateTime, DateTime dateTime, string which)
{
Assert.That(toDateTime.ToStableUniversalTime().RoundToMs(), Is.EqualTo(dateTime.ToStableUniversalTime().RoundToMs()), which);
}
示例7: IsEqualToTheSecond
public static bool IsEqualToTheSecond(this DateTime dateTime, DateTime otherDateTime)
{
return dateTime.ToStableUniversalTime().RoundToSecond().Equals(otherDateTime.ToStableUniversalTime().RoundToSecond());
}
示例8: ToShortestXsdDateTimeString
public static string ToShortestXsdDateTimeString(DateTime dateTime)
{
var timeOfDay = dateTime.TimeOfDay;
var isStartOfDay = timeOfDay.Ticks == 0;
if (isStartOfDay)
return dateTime.ToString(ShortDateTimeFormat);
var hasFractionalSecs = (timeOfDay.Milliseconds != 0)
|| ((timeOfDay.Ticks%TimeSpan.TicksPerMillisecond) != 0);
if (!hasFractionalSecs)
return dateTime.Kind != DateTimeKind.Utc
? dateTime.ToString(DateTimeFormatSecondsUtcOffset)
: dateTime.ToStableUniversalTime().ToString(XsdDateTimeFormatSeconds);
return dateTime.Kind != DateTimeKind.Utc
? dateTime.ToString(DateTimeFormatTicksUtcOffset)
: PclExport.Instance.ToXsdDateTimeString(dateTime);
}
示例9: ToShortestXsdDateTimeString
public static string ToShortestXsdDateTimeString(DateTime dateTime)
{
var timeOfDay = dateTime.TimeOfDay;
var isStartOfDay = timeOfDay.Ticks == 0;
if (isStartOfDay && !JsConfig.SkipDateTimeConversion)
return dateTime.ToString(ShortDateTimeFormat);
var hasFractionalSecs = (timeOfDay.Milliseconds != 0)
|| (timeOfDay.Ticks % TimeSpan.TicksPerMillisecond != 0);
if (JsConfig.SkipDateTimeConversion)
{
if (!hasFractionalSecs)
return dateTime.Kind == DateTimeKind.Local
? dateTime.ToString(DateTimeFormatSecondsUtcOffset)
: dateTime.Kind == DateTimeKind.Unspecified
? dateTime.ToString(DateTimeFormatSecondsNoOffset)
: dateTime.ToStableUniversalTime().ToString(XsdDateTimeFormatSeconds);
return dateTime.Kind == DateTimeKind.Local
? dateTime.ToString(DateTimeFormatTicksUtcOffset)
: dateTime.Kind == DateTimeKind.Unspecified
? dateTime.ToString(DateTimeFormatTicksNoUtcOffset)
: PclExport.Instance.ToXsdDateTimeString(dateTime);
}
if (!hasFractionalSecs)
return dateTime.Kind != DateTimeKind.Utc
? dateTime.ToString(DateTimeFormatSecondsUtcOffset)
: dateTime.ToStableUniversalTime().ToString(XsdDateTimeFormatSeconds);
return dateTime.Kind != DateTimeKind.Utc
? dateTime.ToString(DateTimeFormatTicksUtcOffset)
: PclExport.Instance.ToXsdDateTimeString(dateTime);
}
示例10: ToXsdDateTimeString
public override string ToXsdDateTimeString(DateTime dateTime)
{
return System.Xml.XmlConvert.ToString(dateTime.ToStableUniversalTime(), System.Xml.XmlDateTimeSerializationMode.Utc);
}
示例11: ToShortestXsdDateTimeString
public static string ToShortestXsdDateTimeString(DateTime dateTime)
{
var timeOfDay = dateTime.TimeOfDay;
if (timeOfDay.Ticks == 0)
return dateTime.ToString(ShortDateTimeFormat);
if (timeOfDay.Milliseconds == 0)
return dateTime.Kind != DateTimeKind.Utc
? dateTime.ToString(DateTimeFormatSecondsUtcOffset)
: dateTime.ToStableUniversalTime().ToString(XsdDateTimeFormatSeconds);
return dateTime.Kind != DateTimeKind.Utc
? dateTime.ToString(DateTimeFormatTicksUtcOffset)
: PclExport.Instance.ToXsdDateTimeString(dateTime);
}