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


C# DateTimeOffset.ToLocalTime方法代码示例

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


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

示例1: ChannelMessage

 public ChannelMessage(string id, DateTimeOffset when, string userName, string content)
 {
     this.Id = id;
     this.When = when.ToLocalTime();
     this.User = userName;
     this.Content = content;
 }
开发者ID:nerdfury,项目名称:JabbR.Desktop,代码行数:7,代码来源:ChannelMessage.cs

示例2: MeMessage

 public MeMessage(DateTimeOffset when, string userName, string content)
 {
     this.Content = content;
     this.When = when.ToLocalTime();
     this.Time = this.When.ToString("h:mm:ss tt");
     this.User = userName;
 }
开发者ID:modulexcite,项目名称:JabbR.Desktop,代码行数:7,代码来源:MeMessage.cs

示例3: GetNextIncludedTimeUtc

        /// <summary>
        /// Determine the next time (in milliseconds) that is 'included' by the
        /// Calendar after the given time. Return the original value if timeStamp is
        /// included. Return DateTime.MinValue if all days are excluded.
        /// <para>
        /// Note that this Calendar is only has full-day precision.
        /// </para>
        /// </summary>
        /// <param name="timeUtc"></param>
        /// <returns></returns>
        public override DateTimeOffset GetNextIncludedTimeUtc(DateTimeOffset timeUtc)
        {
            if (base.AreAllDaysExcluded())
            {
                return DateTime.MinValue;
            }

            // Call base calendar implementation first
            DateTimeOffset baseTime = base.GetNextIncludedTimeUtc(timeUtc);
            if ((baseTime != DateTimeOffset.MinValue) && (baseTime > timeUtc))
            {
                timeUtc = baseTime;
            }

            // Get timestamp for 00:00:00
            //DateTime d = timeUtc.Date;   --commented out for local time impl
            DateTime d = timeUtc.ToLocalTime().Date;

            if (!IsDayExcluded(d.DayOfWeek))
            {
                return timeUtc;
            } // return the original value

            while (IsDayExcluded(d.DayOfWeek))
            {
                d = d.AddDays(1);
            }

            return d;
        }
开发者ID:bobbyfox,项目名称:AndrewSmith.Quartz.TextToSchedule,代码行数:40,代码来源:LocalWeeklyCalendar.cs

示例4: 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

示例5: OffsetUtc

        public static string OffsetUtc(DateTimeOffset time)
        {
            if (time == default(DateTimeOffset))
                return "";

            var now = DateTimeOffset.UtcNow;
            var offset = now - time;

            if (Math.Abs(offset.TotalDays) > 7)
            {
                return time.ToLocalTime().ToString("MMMM dd, yyyy", CultureInfo.InvariantCulture);
            }

            if (offset > TimeSpan.Zero)
            {
                return PositiveTimeSpan(offset) + " ago";
            }
            return PositiveTimeSpan(-offset) + " from now";
        }
开发者ID:abdullin,项目名称:Farleyfile,代码行数:19,代码来源:FormatEvil.cs

示例6: ToLocalTime

 public static void ToLocalTime()
 {
     DateTimeOffset dateTimeOffset = new DateTimeOffset(new DateTime(1000, DateTimeKind.Utc));
     Assert.Equal(new DateTimeOffset(dateTimeOffset.UtcDateTime.ToLocalTime()), dateTimeOffset.ToLocalTime());
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:5,代码来源:DateTimeOffsetTests.cs

示例7: Main

		private static int Main(string[] args)
		{
			CommandLineParser clp = new CommandLineParser();
			clp.AddKnownOption("a", "assembly-info");
			clp.AddKnownOption("", "test-b36min");
			clp.AddKnownOption("b", "test-bmin");
			clp.AddKnownOption("f", "format", true);
			clp.AddKnownOption("h", "help");
			clp.AddKnownOption("i", "ignore-missing");
			clp.AddKnownOption("m", "multi-project");
			clp.AddKnownOption("r", "revision");
			clp.AddKnownOption("s", "restore");
			clp.AddKnownOption("v", "version");
			clp.AddKnownOption("x", "test-xmin");
			clp.AddKnownOption("B", "de-bmin");
			clp.AddKnownOption("", "de-b36min");
			clp.AddKnownOption("D", "de-dmin");
			clp.AddKnownOption("I", "only-infver");
			clp.AddKnownOption("M", "stop-if-modified");
			clp.AddKnownOption("X", "de-xmin");
			clp.AddKnownOption("", "debug");

			debugOutput = clp.IsOptionSet("debug");

			if (clp.IsOptionSet("h") || clp.IsOptionSet("v"))
			{
				HandleHelp(clp.IsOptionSet("h"));
				return 0;
			}
			if (clp.IsOptionSet("X"))
			{
				int baseYear;
				if (!int.TryParse(clp.GetArgument(0), out baseYear))
				{
					Console.Error.WriteLine("Invalid argument: Base year expected");
					return 1;
				}
				string xmin = clp.GetArgument(1).Trim().ToLowerInvariant();
				DateTime time = DehexMinutes(baseYear, xmin);
				if (time == DateTime.MinValue)
				{
					Console.Error.WriteLine("Invalid xmin value.");
					return 0;
				}
				Console.WriteLine(time.ToString("yyyy-MM-dd HH:mm") + " UTC");
				Console.WriteLine(time.ToLocalTime().ToString("yyyy-MM-dd HH:mm K"));
				return 0;
			}
			if (clp.IsOptionSet("B"))
			{
				int baseYear;
				if (!int.TryParse(clp.GetArgument(0), out baseYear))
				{
					Console.Error.WriteLine("Invalid argument: Base year expected");
					return 1;
				}
				string bmin = clp.GetArgument(1).Trim().ToLowerInvariant();
				DateTime time = Debase28Minutes(baseYear, bmin);
				if (time == DateTime.MinValue)
				{
					Console.Error.WriteLine("Invalid bmin value.");
					return 0;
				}
				Console.WriteLine(time.ToString("yyyy-MM-dd HH:mm") + " UTC");
				Console.WriteLine(time.ToLocalTime().ToString("yyyy-MM-dd HH:mm K"));
				return 0;
			}
			if (clp.IsOptionSet("de-b36min"))
			{
				int baseYear;
				if (!int.TryParse(clp.GetArgument(0), out baseYear))
				{
					Console.Error.WriteLine("Invalid argument: Base year expected");
					return 1;
				}
				string bmin = clp.GetArgument(1).Trim().ToLowerInvariant();
				DateTime time = Debase36Minutes(baseYear, bmin);
				if (time == DateTime.MinValue)
				{
					Console.Error.WriteLine("Invalid b36min value.");
					return 0;
				}
				Console.WriteLine(time.ToString("yyyy-MM-dd HH:mm") + " UTC");
				Console.WriteLine(time.ToLocalTime().ToString("yyyy-MM-dd HH:mm K"));
				return 0;
			}
			if (clp.IsOptionSet("D"))
			{
				int baseYear;
				if (!int.TryParse(clp.GetArgument(0), out baseYear))
				{
					Console.Error.WriteLine("Invalid argument: Base year expected");
					return 1;
				}
				string dmin = clp.GetArgument(1).Trim();
				DateTime time = DedecMinutes(baseYear, dmin);
				if (time == DateTime.MinValue)
				{
					Console.Error.WriteLine("Invalid dmin value.");
					return 0;
//.........这里部分代码省略.........
开发者ID:ygoe,项目名称:GitRevisionTool,代码行数:101,代码来源:Program.cs

示例8: GenerateHeader

        public static string GenerateHeader(string authorName, string authorFullEmail,string authoredAge, DateTimeOffset authorTime, string committerName, string committerFullEmail,string commitedAge, DateTimeOffset commitTime, Guid commitGuid)
        {
            var authorField =GenerateHeaderField( Strings.GetAuthorText());
            var authorDateField=GenerateHeaderField(Strings.GetAuthorDateText());
            var committerField = GenerateHeaderField(Strings.GetCommitterText());
            var commitDate = GenerateHeaderField(Strings.GetCommitDateText());
            var commitHashField = GenerateHeaderField(Strings.GetCommitHashText());
            var authorEmail = GetEmail(authorFullEmail);
            var committerEmail = GetEmail(committerFullEmail);

            var expectedHeader = authorField + "<a href='mailto:" + HttpUtility.HtmlAttributeEncode(authorEmail) + "'>" + HttpUtility.HtmlEncode(authorFullEmail) + "</a>" + Environment.NewLine +
                                 authorDateField + authoredAge + " (" + authorTime.ToLocalTime().ToString("ddd MMM dd HH':'mm':'ss yyyy") + ")" + Environment.NewLine +
                                  committerField + "<a href='mailto:" + HttpUtility.HtmlAttributeEncode(committerEmail) + "'>" + HttpUtility.HtmlEncode(committerFullEmail) + "</a>" + Environment.NewLine +
                                  commitDate+commitedAge+" (" + commitTime.ToLocalTime().ToString("ddd MMM dd HH':'mm':'ss yyyy") + ")" + Environment.NewLine +
                                  commitHashField + commitGuid;

            return expectedHeader;
        }
开发者ID:ImaginaryDevelopment,项目名称:gitextensions,代码行数:18,代码来源:CommitData.cs

示例9: GetLastAccessTime

 internal static DateTimeOffset GetLastAccessTime(string path)
 {
     string str = LongPath.NormalizePath(path);
     new FileIOPermission(FileIOPermissionAccess.Read, new string[] { str }, false, false).Demand();
     string str2 = Path.AddLongPathPrefix(str);
     Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA();
     int errorCode = File.FillAttributeInfo(str2, ref data, false, false);
     if (errorCode != 0)
     {
         __Error.WinIOError(errorCode, str);
     }
     long fileTime = (data.ftLastAccessTimeHigh << 0x20) | data.ftLastAccessTimeLow;
     DateTimeOffset offset = new DateTimeOffset(DateTime.FromFileTimeUtc(fileTime).ToLocalTime());
     return offset.ToLocalTime();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:15,代码来源:LongPathFile.cs

示例10: NotificationMessage

 public NotificationMessage(DateTimeOffset when, string content)
 {
     this.When = when.ToLocalTime();
     this.Time = this.When.ToString("h:mm:ss tt");
     this.Content = content;
 }
开发者ID:modulexcite,项目名称:JabbR.Desktop,代码行数:6,代码来源:NotificationMessage.cs

示例11: GetLastWriteTime

 public DateTimeOffset GetLastWriteTime(string path)
 {
     if (path == null)
     {
         throw new ArgumentNullException("path");
     }
     if (path.Trim().Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"), "path");
     }
     if (this.m_bDisposed)
     {
         throw new ObjectDisposedException(null, Environment.GetResourceString("IsolatedStorage_StoreNotOpen"));
     }
     if (this.m_closed)
     {
         throw new InvalidOperationException(Environment.GetResourceString("IsolatedStorage_StoreNotOpen"));
     }
     this.m_fiop.Assert();
     this.m_fiop.PermitOnly();
     string str2 = LongPath.NormalizePath(this.GetFullPath(path));
     try
     {
         Demand(new FileIOPermission(FileIOPermissionAccess.Read, new string[] { str2 }, false, false));
     }
     catch
     {
         DateTimeOffset offset3 = new DateTimeOffset(0x641, 1, 1, 0, 0, 0, TimeSpan.Zero);
         return offset3.ToLocalTime();
     }
     DateTimeOffset lastWriteTime = LongPathFile.GetLastWriteTime(str2);
     CodeAccessPermission.RevertAll();
     return lastWriteTime;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:34,代码来源:IsolatedStorageFile.cs

示例12: OldEraToLocalTime

		public void OldEraToLocalTime ()
		{
			TimeSpan offset = TimeSpan.Zero;
			var dto = new DateTimeOffset (new DateTime (1900, 1, 1).Ticks, offset);

			// Should never throw
			dto.ToLocalTime ();
		}
开发者ID:razzfazz,项目名称:mono,代码行数:8,代码来源:TimeZoneTest.cs

示例13: CreateCalendarTime

 private DateTimeOffset CreateCalendarTime(DateTimeOffset dateTime)
 {
     return dateTime.ToLocalTime();
 }
开发者ID:herrmic,项目名称:quartznet,代码行数:4,代码来源:DailyTimeIntervalTriggerImpl.cs

示例14: GetFireTimeAfter

        /// <summary>
        /// Returns the next time at which the <see cref="IDailyTimeIntervalTrigger" /> will
        /// fire, after the given time. If the trigger will not fire after the given
        /// time, <see langword="null" /> will be returned.
        /// </summary>
        /// <param name="afterTime"></param>
        /// <returns></returns>
        public override DateTimeOffset? GetFireTimeAfter(DateTimeOffset? afterTime)
        {
            // Check if trigger has completed or not.
            if (complete)
            {
                return null;
            }

            // Check repeatCount limit
            if (repeatCount != RepeatIndefinitely && timesTriggered > repeatCount)
            {
                return null;
            }

            // a. Increment afterTime by a second, so that we are comparing against a time after it!
            if (afterTime == null)
            {
                afterTime = SystemTime.UtcNow().AddSeconds(1);
            }
            else
            {
                afterTime = afterTime.Value.AddSeconds(1);
            }

            // now change to local time zone
            afterTime = afterTime.Value.ToLocalTime();

            // b.Check to see if afterTime is after endTimeOfDay or not.
            // If yes, then we need to advance to next day as well.
            bool afterTimePassEndTimeOfDay = false;
            if (endTimeOfDay != null)
            {
                afterTimePassEndTimeOfDay = afterTime.Value > endTimeOfDay.GetTimeOfDayForDate(afterTime).Value;
            }
            DateTimeOffset? fireTime = AdvanceToNextDayOfWeek(afterTime.Value, afterTimePassEndTimeOfDay);
            if (fireTime == null)
            {
                return null;
            }

            // c. Calculate and save fireTimeEndDate variable for later use
            DateTimeOffset fireTimeEndDate;
            if (endTimeOfDay == null)
            {
                fireTimeEndDate = new TimeOfDay(23, 59, 59).GetTimeOfDayForDate(fireTime).Value;
            }
            else
            {
                fireTimeEndDate = endTimeOfDay.GetTimeOfDayForDate(fireTime).Value;
            }

            // e. Check fireTime against startTime or startTimeOfDay to see which go first.
            DateTimeOffset fireTimeStartDate = startTimeOfDay.GetTimeOfDayForDate(fireTime).Value;
            if (fireTime < startTimeUtc && startTimeUtc < fireTimeStartDate)
            {
                return fireTimeStartDate;
            }
            else if (fireTime < startTimeUtc && startTimeUtc > fireTimeStartDate)
            {
                return startTimeUtc;
            }
            else if (fireTime > startTimeUtc && fireTime < fireTimeStartDate)
            {
                return fireTimeStartDate;
            }

            // Always adjust the startTime to be startTimeOfDay
            startTimeUtc = fireTimeStartDate.ToUniversalTime();

            // f. Continue to calculate the fireTime by incremental unit of intervals.
            long secondsAfterStart = (long) (fireTime.Value - startTimeUtc.ToLocalTime()).TotalSeconds;
            long repeatLong = RepeatInterval;

            DateTimeOffset sTime = startTimeUtc.ToLocalTime();
            IntervalUnit repeatUnit = RepeatIntervalUnit;
            if (repeatUnit == IntervalUnit.Second)
            {
                long jumpCount = secondsAfterStart/repeatLong;
                if (secondsAfterStart%repeatLong != 0)
                {
                    jumpCount++;
                }

                sTime = sTime.AddSeconds(RepeatInterval*(int) jumpCount);
                fireTime = sTime;
            }
            else if (repeatUnit == IntervalUnit.Minute)
            {
                long jumpCount = secondsAfterStart/(repeatLong*60L);
                if (secondsAfterStart%(repeatLong*60L) != 0)
                {
                    jumpCount++;
                }
//.........这里部分代码省略.........
开发者ID:herrmic,项目名称:quartznet,代码行数:101,代码来源:DailyTimeIntervalTriggerImpl.cs

示例15: SummaryTable

 /// <summary>
 /// Gets the statistical information
 /// </summary>
 /// <param name="totalCasesNum">The number of total cases</param>
 /// <param name="passedNum">The number of passed cases</param>
 /// <param name="failedNum">The number of failed cases</param>
 /// <param name="testRunStartTime">The start time of the run</param>
 /// <param name="testRunEndTime">The end time of the run</param>
 /// <returns>Return statistical information about this test</returns>
 public string SummaryTable(long totalCasesNum,
                        long passedNum,
                        long failedNum,
                        DateTimeOffset testRunStartTime,
                        DateTimeOffset testRunEndTime)
 {
     DataType.RunSummary sry = new DataType.RunSummary()
     {
         TotalCount = totalCasesNum,
         FailedCount = failedNum,
         PassedCount = passedNum,
         InconclusiveCount = totalCasesNum - passedNum - failedNum,
         PassRate = totalCasesNum == 0 ? 0 : (float)passedNum * 100 / totalCasesNum,
         StartTime = testRunStartTime.ToLocalTime().ToString("MM/dd/yyyy HH:mm:ss"),
         EndTime = testRunEndTime.ToLocalTime().ToString("MM/dd/yyyy HH:mm:ss"),
         Duration = testRunEndTime.Subtract(testRunStartTime).ToString(@"hh\:mm\:ss")
     };
     return (serializer.Serialize(sry));
 }
开发者ID:LiuXiaotian,项目名称:ProtocolTestFramework,代码行数:28,代码来源:TxtToJSON.cs


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