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


C# LocalDateTime.InZoneLeniently方法代码示例

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


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

示例1: ExtractDateTimeFromExif

        /// <summary>
        /// EXIF DateTime is stored as a string - "yyyy:MM:dd hh:mm:ss" in 24 hour format.
        /// 
        /// Since EXIF datetime does not store timezone info, making the time ambiguous, we grab the user's specified timezone
        /// and assume the image was taken in that timezone.
        /// 
        /// If we don't have a parseable datetime, we set the time to now.
        /// </summary>
        public DateTime ExtractDateTimeFromExif(string dateTimeExif, string timezone)
        {
            var dateTimeStringComponents = dateTimeExif.Split(new[] { ':', ' ' });

            if (dateTimeExif != string.Empty && dateTimeStringComponents.Count() == 6)
            {
                var dateTimeIntComponents = new int[dateTimeStringComponents.Count()];

                for (var i = 0; i < dateTimeStringComponents.Length; i++)
                {
                    int convertedSegment;
                    if (Int32.TryParse(dateTimeStringComponents[i], out convertedSegment))
                    {
                        dateTimeIntComponents[i] = convertedSegment;
                    }
                }

                // Get data into a local time object (no time zone specified)
                var localDateTime = new LocalDateTime(
                        dateTimeIntComponents[0], // year
                        dateTimeIntComponents[1], // month
                        dateTimeIntComponents[2], // day
                        dateTimeIntComponents[3], // hour
                        dateTimeIntComponents[4], // minute
                        dateTimeIntComponents[5], // second
                        CalendarSystem.Iso);

                // Put the local date time into a timezone
                var zonedDateTime = localDateTime.InZoneLeniently(DateTimeZoneProviders.Tzdb[timezone]);

                // Get the UTC date time of the given local date time in the given time zone
                return zonedDateTime.WithZone(DateTimeZone.Utc).ToDateTimeUtc();
            }

            return DateTime.UtcNow;
        }
开发者ID:Bowerbird,项目名称:bowerbird-web,代码行数:44,代码来源:DateTimeZoneService.cs

示例2: WindowsTimeZone

        private DateTime WindowsTimeZone(EventDateTime time) {
            DateTime theDate = DateTime.Parse(time.DateTime ?? time.Date);
            if (time.TimeZone == null) return theDate;

            LocalDateTime local = new LocalDateTime(theDate.Year, theDate.Month, theDate.Day, theDate.Hour, theDate.Minute);
            DateTimeZone zone = DateTimeZoneProviders.Tzdb[time.TimeZone];
            ZonedDateTime zonedTime = local.InZoneLeniently(zone);
            DateTime zonedUTC = zonedTime.ToDateTimeUtc();
            log.Fine("IANA Timezone \"" + time.TimeZone + "\" mapped to \""+ zone.Id.ToString() +"\" with a UTC of "+ zonedUTC.ToString("dd/MM/yyyy HH:mm:ss"));
            return zonedUTC;
        }
开发者ID:EduShareGeorgian,项目名称:OutlookGoogleSync,代码行数:11,代码来源:OutlookOld.cs

示例3: InZoneLeniently_ReturnsStartOfSecondInterval

 public void InZoneLeniently_ReturnsStartOfSecondInterval()
 {
     var local = new LocalDateTime(2009, 3, 8, 2, 30, 0);
     var zoned = local.InZoneLeniently(Pacific);
     Assert.AreEqual(new LocalDateTime(2009, 3, 8, 3, 30, 0), zoned.LocalDateTime);
     Assert.AreEqual(Offset.FromHours(-7), zoned.Offset);
 }
开发者ID:nicklbailey,项目名称:nodatime,代码行数:7,代码来源:LocalDateTimeTest.cs

示例4: InZoneLeniently_AmbiguousTime_ReturnsEarlierMapping

 public void InZoneLeniently_AmbiguousTime_ReturnsEarlierMapping()
 {
     var local = new LocalDateTime(2009, 11, 1, 1, 30, 0);
     var zoned = local.InZoneLeniently(Pacific);
     Assert.AreEqual(local, zoned.LocalDateTime);
     Assert.AreEqual(Offset.FromHours(-7), zoned.Offset);
 }
开发者ID:nicklbailey,项目名称:nodatime,代码行数:7,代码来源:LocalDateTimeTest.cs


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