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


C# DateTimeOffset.ToUniversalTime方法代码示例

本文整理汇总了C#中DateTimeOffset.ToUniversalTime方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeOffset.ToUniversalTime方法的具体用法?C# DateTimeOffset.ToUniversalTime怎么用?C# DateTimeOffset.ToUniversalTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTimeOffset的用法示例。


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

示例1: DateTimeOffset_Can_Specifity_Your_Local_Time_From_Utc_Point_Of_View

        public void DateTimeOffset_Can_Specifity_Your_Local_Time_From_Utc_Point_Of_View()
        {
            var jonsTime = new DateTimeOffset(2011, 4, 1, 21, 24, 0, TimeSpan.FromHours(1));
            var localTime = new DateTime(2011, 4, 1, 20, 24, 0);

            Assert.That(jonsTime.ToUniversalTime().Hour, Is.EqualTo(localTime.Hour));
        }
开发者ID:xianxingg,项目名称:JonSkeetCSharp4Examples,代码行数:7,代码来源:DateTimeExample.cs

示例2: ToAtomString

 internal static string ToAtomString(DateTimeOffset dateTime)
 {
     if (dateTime.Offset == zeroOffset)
     {
         return dateTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture);
     }
     return dateTime.ToString("yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture);
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:ODataAtomConvert.cs

示例3: AsString

 private string AsString(DateTimeOffset dateTime)
 {
     if (dateTime.Offset == zeroOffset)
     {
         return dateTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture);
     }
     return dateTime.ToString("yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:Atom10FeedFormatter.cs

示例4: WriteDate

 public void WriteDate(DateTimeOffset datetime)
 {
     this.writeAmf3Type(Amf3Type.Date);
     UInt29 remainIndex = 0;
     remainIndex.WriteAsRefTo(false,this.writer_);
     var utcTime = datetime.ToUniversalTime();
     var totalMilliseconds = utcTime.ToUnixTime();
     this.writer_.WriteDouble(totalMilliseconds);
 }
开发者ID:qwerty2501,项目名称:PartialActionScript.Data.Amf,代码行数:9,代码来源:Amf3Writer.cs

示例5: ConvertDateTimeValue_NonStandardPrimitives_DefaultTimeZoneInfo

        public void ConvertDateTimeValue_NonStandardPrimitives_DefaultTimeZoneInfo(DateTimeOffset valueToConvert)
        {
            // Arrange & Act
            TimeZoneInfoHelper.TimeZone = null;
            object actual = EdmPrimitiveHelpers.ConvertPrimitiveValue(valueToConvert, typeof(DateTime));

            // Assert
            DateTime dt = Assert.IsType<DateTime>(actual);
            Assert.Equal(valueToConvert.ToUniversalTime().ToOffset(TimeZoneInfo.Local.BaseUtcOffset).DateTime, dt);
        }
开发者ID:billwaddyjr,项目名称:WebApi,代码行数:10,代码来源:EdmPrimitiveHelpersTest.cs

示例6: DateTimeOffSet

        public void DateTimeOffSet()
        {
            //System.DateTimeOffset (.NET 2.0SP1 / .NET 3.5)

            DateTimeOffset myTime = new DateTimeOffset(2015, 11, 12, 9, 13, 0, TimeSpan.FromHours(1));
            Console.WriteLine(  myTime);
            Console.WriteLine(myTime.ToUniversalTime());

            //System.TimeZoneInfo (.NET 3.5)
        }
开发者ID:ussimandias,项目名称:MasteringCSharpNUnitTests,代码行数:10,代码来源:DateTest.cs

示例7: ConvertDateTimeValue_NonStandardPrimitives_CustomTimeZoneInfo

        public void ConvertDateTimeValue_NonStandardPrimitives_CustomTimeZoneInfo(DateTimeOffset valueToConvert)
        {
            // Arrange & Act
            TimeZoneInfoHelper.TimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            object actual = EdmPrimitiveHelpers.ConvertPrimitiveValue(valueToConvert, typeof(DateTime));

            // Assert
            DateTime dt = Assert.IsType<DateTime>(actual);
            Assert.Equal(valueToConvert.ToUniversalTime().ToOffset(new TimeSpan(-8, 0, 0)).DateTime, dt);
        }
开发者ID:billwaddyjr,项目名称:WebApi,代码行数:10,代码来源:EdmPrimitiveHelpersTest.cs

示例8: AsString

 private string AsString(DateTimeOffset dateTime)
 {
     if (dateTime.Offset == Atom10FeedFormatter.zeroOffset)
     {
         return dateTime.ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss Z", CultureInfo.InvariantCulture);
     }
     StringBuilder builder = new StringBuilder(dateTime.ToString("ddd, dd MMM yyyy HH:mm:ss zzz", CultureInfo.InvariantCulture));
     builder.Remove(builder.Length - 3, 1);
     return builder.ToString();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:10,代码来源:Rss20FeedFormatter.cs

示例9: TIME

 public static XElement TIME(string name, DateTimeOffset time)
 {
     var t1 = time.ToUniversalTime();
     var t2 = time.ToLocalTime().ToString("G");
     return new XElement(
         XN.time,
         PROP(name),
         new XAttribute(XN.datetime, t1),
         t2);
 }
开发者ID:pudwinkie,项目名称:neith,代码行数:10,代码来源:XIVExtensons.cs

示例10: UserList

        public UserList(string usersFile, DateTimeOffset startOfWeek)
            : this(usersFile)
        {
            StartOfPeriod = startOfWeek.ToUniversalTime();
            EndOfPeriod = StartOfPeriod.AddDays(7);

            // We only count events attached to posts (questions or answers) that we created at most 3 days before
            // the week starts. The idea is to not keep rewarding users for old entries that are getting upticks
            FirstStackOverflowPost = QueryHelpers.GetIdOfFirstPostOfDay(StartOfPeriod.AddDays(-3));
        }
开发者ID:davidebbo,项目名称:ForumScorer,代码行数:10,代码来源:UserList.cs

示例11: DateTimeOffset

        public void DateTimeOffset()
        {
            // System.DateTimeOffset (.NET 3.5)
            DateTimeOffset axelsTime = new DateTimeOffset(2011, 4, 1, 21, 24, 0, TimeSpan.FromHours(1));
            //Console.WriteLine(axelsTime);
            //Console.WriteLine(axelsTime.ToUniversalTime());
            DateTimeOffset robsTime = new DateTimeOffset(2011, 4, 1, 10, 24, 0, TimeSpan.FromHours(-10));

            Assert.AreEqual(axelsTime, robsTime);
            Assert.AreEqual(axelsTime.ToUniversalTime(), robsTime.ToUniversalTime());
        }
开发者ID:Zedronar,项目名称:skeet-csharp4,代码行数:11,代码来源:DateTimeOffset.cs

示例12: AbsoluteTimer

        public WaitHandle AbsoluteTimer(DateTimeOffset expireAt)
        {
            var handle = CreateWaitableTimer(IntPtr.Zero, true, null);

            var dueTime = expireAt.ToUniversalTime().ToFileTime();

            SetWaitableTimer(handle, ref dueTime, 0, IntPtr.Zero, IntPtr.Zero, false);

            var safeHandle = new SafeWaitHandle(handle, true);

            return new TimerWaitHandle(safeHandle);
        }
开发者ID:hash,项目名称:trigger.net,代码行数:12,代码来源:Win32Native.cs

示例13: CopyFromDocument

        public void CopyFromDocument()
        {
            var mapper = CreateMapper();

            var doc = new Document();

            var ts = new DateTimeOffset(new DateTime(2013, 1, 1));
            doc.Add(new Field("TimeStampOffset", ts.ToUniversalTime().Ticks.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));

            mapper.CopyFromDocument(doc, 0, this);

            Assert.That(TimeStampOffset, Is.EqualTo(ts));
        }
开发者ID:benjaminramey,项目名称:Lucene.Net.Linq,代码行数:13,代码来源:FieldMappingInfoBuilderNumericDateTimeOffsetTests.cs

示例14: modified

        public modified()
        {
            point_in_time = new DateTimeOffset(2011,09,24,22,00,0,0, 2.Hours());

            // last-modified: 24 Sep 2011 23:11:00 +0200 (21:00:00 GMT)
            given_resource(
                "/resource",
                resource=>resource.Map<ResourceWithLastModified>().LastModified(_=> _.LastModified),
                new ResourceWithLastModified { LastModified = point_in_time + 1.Hours() });

            // if-modified-since: 24 Sep 2011 22:00:00 +0200 (20:00:00 GMT)
            given_request_header("if-modified-since", point_in_time.ToUniversalTime().ToString("R"));
            when_executing_request("/resource");
        }
开发者ID:shekelator,项目名称:openrasta-caching,代码行数:14,代码来源:modified.cs

示例15: DateTimeSerializeToJSON

 private string DateTimeSerializeToJSON(DateTime dateTime)
 {
     var value = new DateTimeOffset(dateTime);
     var kind = dateTime.Kind;
     var num = ((value.ToUniversalTime().Ticks - new DateTime(0x7b2, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks) / 0x2710L);
     var str = string.Empty;
     switch (kind)
     {
         case DateTimeKind.Unspecified:
         case DateTimeKind.Local:
             TimeSpan offset = value.Offset;
             str = offset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + offset.Minutes.ToString("00;00", CultureInfo.InvariantCulture);
             break;
     }
     return ("\"\\/Date(" + num.ToString(CultureInfo.InvariantCulture) + str + ")\\/\"");
 }
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:16,代码来源:UploadProgressStatistic.cs


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