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


C# DateTime.ToStableUniversalTime方法代码示例

本文整理汇总了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);
		}
开发者ID:houlgap,项目名称:ServiceStack.Text,代码行数:12,代码来源:DateTimeSerializer.cs

示例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)));
		}
开发者ID:rickardn,项目名称:ServiceStack.Text,代码行数:19,代码来源:DateTimeSerializerTests.cs

示例3: ToXsdDateTimeString

		public static string ToXsdDateTimeString(DateTime dateTime)
		{
			return XmlConvert.ToString(dateTime.ToStableUniversalTime(), XmlDateTimeSerializationMode.Utc);
		}
开发者ID:houlgap,项目名称:ServiceStack.Text,代码行数:4,代码来源:DateTimeSerializer.cs

示例4: ToDateTimeString

		public static string ToDateTimeString(DateTime dateTime)
		{
			return dateTime.ToStableUniversalTime().ToString(XsdDateTimeFormat);
		}
开发者ID:houlgap,项目名称:ServiceStack.Text,代码行数:4,代码来源:DateTimeSerializer.cs

示例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
        }
开发者ID:ChrisRomp,项目名称:Xero-Net,代码行数:8,代码来源:DateTimeSerializer.cs

示例6: AssertDatesAreEqual

        private void AssertDatesAreEqual(DateTime toDateTime, DateTime dateTime, string which)
        {
			Assert.That(toDateTime.ToStableUniversalTime().RoundToMs(), Is.EqualTo(dateTime.ToStableUniversalTime().RoundToMs()), which);
        }
开发者ID:rickardn,项目名称:ServiceStack.Text,代码行数:4,代码来源:DateTimeSerializerTests.cs

示例7: IsEqualToTheSecond

 public static bool IsEqualToTheSecond(this DateTime dateTime, DateTime otherDateTime)
 {
     return dateTime.ToStableUniversalTime().RoundToSecond().Equals(otherDateTime.ToStableUniversalTime().RoundToSecond());
 }
开发者ID:rsafier,项目名称:ServiceStack.Text,代码行数:4,代码来源:DateTimeExtensions.cs

示例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);
        }
开发者ID:GavinHwa,项目名称:ServiceStack.Text,代码行数:19,代码来源:DateTimeSerializer.cs

示例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);
        }
开发者ID:sxagan,项目名称:ServiceStack.Text,代码行数:36,代码来源:DateTimeSerializer.cs

示例10: ToXsdDateTimeString

 public override string ToXsdDateTimeString(DateTime dateTime)
 {
     return System.Xml.XmlConvert.ToString(dateTime.ToStableUniversalTime(), System.Xml.XmlDateTimeSerializationMode.Utc);
 }
开发者ID:CLupica,项目名称:ServiceStack,代码行数:4,代码来源:IosPclExportWithXml.cs

示例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);
        }
开发者ID:danbarua,项目名称:ServiceStack.Text,代码行数:16,代码来源:DateTimeSerializer.cs


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