當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。