12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading;
- namespace Ips.Library.Basic
- {
- public static class DateTimeUtil
- {
- public const string DefaultDisplayFmt = "yyyy-MM-dd HH:mm:ss";
- public const string DefaultNumFmt = "yyyyMMddHHmmss";
- public static readonly DateTime _DT1970 = new DateTime(1970, 1, 1, 8, 0, 0);
- public static long To1970s(DateTime source)
- {
- return (long)(source - _DT1970).TotalSeconds;
- }
- public static long To1970ms(DateTime source)
- {
- return (long)(source - _DT1970).TotalMilliseconds;
- }
- public static DateTime From1970s(long seconds)
- {
- return _DT1970.AddSeconds(seconds);
- }
- public static DateTime From1970ms(long milliseconds)
- {
- return _DT1970.AddMilliseconds(milliseconds);
- }
- public static void WaitTime(DateTime time)
- {
- if (time <= DateTime.Now) return;
- while (true)
- {
- Thread.Sleep(100);
- if (time <= DateTime.Now) break;
- }
- }
- }
- }
|