You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
5.0 KiB
149 lines
5.0 KiB
using Apewer.Internals;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Apewer
|
|
{
|
|
|
|
/// <summary>时钟。</summary>
|
|
public class ClockUtility
|
|
{
|
|
|
|
/// <summary>表示当前时钟的文本,显示为易于阅读的格式。</summary>
|
|
public static string Lucid
|
|
{
|
|
get { return ClockValue.Current.Lucid; }
|
|
}
|
|
|
|
/// <summary>表示当前时钟的文本,显示为连续的数字。</summary>
|
|
public static string Compact
|
|
{
|
|
get { return ClockValue.Current.Compact; }
|
|
}
|
|
|
|
/// <summary>获取当前本地时间以秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。</summary>
|
|
public static long SecondStamp()
|
|
{
|
|
return ClockHelper.Stamp(new DateTime(1970, 1, 1, 0, 0, 0, 0), false);
|
|
}
|
|
|
|
/// <summary>获取指定时间以秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。</summary>
|
|
public static long SecondStamp(DateTime datetime)
|
|
{
|
|
return ClockHelper.Stamp(datetime, false);
|
|
}
|
|
|
|
/// <summary>获取当前本地时间以毫秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。</summary>
|
|
public static long MilliSecondStamp()
|
|
{
|
|
return ClockHelper.Stamp(new DateTime(1970, 1, 1, 0, 0, 0, 0), true);
|
|
}
|
|
|
|
/// <summary>获取指定时间以毫秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。</summary>
|
|
public static long MilliSecondStamp(DateTime datetime)
|
|
{
|
|
return ClockHelper.Stamp(datetime, true);
|
|
}
|
|
|
|
/// <summary>获取 UTC 时间。</summary>
|
|
public static DateTime UtcDateTime
|
|
{
|
|
get { return DateTime.UtcNow; }
|
|
}
|
|
|
|
/// <summary>获取 UTC 时间以秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。</summary>
|
|
public static long UtcSecondStamp
|
|
{
|
|
get { return ClockHelper.Stamp(DateTime.UtcNow, false); }
|
|
}
|
|
|
|
/// <summary>获取 UTC 时间以毫秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。</summary>
|
|
public static long UtcMilliSecondStamp
|
|
{
|
|
get { return ClockHelper.Stamp(DateTime.UtcNow, true); }
|
|
}
|
|
|
|
/// <summary>获取本地时间。</summary>
|
|
public static DateTime LocalDateTime
|
|
{
|
|
get { return DateTime.Now; }
|
|
}
|
|
|
|
/// <summary>获取本地时间以秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。</summary>
|
|
public static long LocalSecondStamp
|
|
{
|
|
get { return ClockHelper.Stamp(DateTime.Now, false); }
|
|
}
|
|
|
|
/// <summary>获取本地时间以毫秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。</summary>
|
|
public static long LocalMilliSecondStamp
|
|
{
|
|
get { return ClockHelper.Stamp(DateTime.Now, true); }
|
|
}
|
|
|
|
/// <summary>转换毫秒时间戳到易于阅读的文本。</summary>
|
|
public static string ToLucid(long stamp)
|
|
{
|
|
return ClockValue.Create(stamp).Lucid;
|
|
}
|
|
|
|
/// <summary>转换 DateTime 对象到易于阅读的文本。</summary>
|
|
public static string ToLucid(DateTime datetime)
|
|
{
|
|
return ClockValue.Create(datetime).Lucid;
|
|
}
|
|
|
|
/// <summary>转换 DateTime 对象到易于阅读的文本。</summary>
|
|
public static string ToLucidDate(DateTime datetime)
|
|
{
|
|
return ClockValue.Create(datetime).LucidDate;
|
|
}
|
|
|
|
/// <summary>转换 DateTime 对象到易于阅读的文本。</summary>
|
|
public static string ToLucidTime(DateTime datetime, bool millisconds = false)
|
|
{
|
|
var time = ClockValue.Create(datetime).LucidTime;
|
|
if (!millisconds) time = time.Substring(0, time.Length - 4);
|
|
return time;
|
|
}
|
|
|
|
/// <summary>转换毫秒时间戳到紧凑文本。</summary>
|
|
public static string ToCompact(long stamp)
|
|
{
|
|
return ClockValue.Create(stamp).Compact;
|
|
}
|
|
|
|
/// <summary>转换 DateTime 对象到紧凑文本。</summary>
|
|
public static string ToCompact(DateTime datetime)
|
|
{
|
|
return ClockValue.Create(datetime).Compact;
|
|
}
|
|
|
|
/// <summary>判断闰年。</summary>
|
|
public static bool LeapYear(int year)
|
|
{
|
|
return ClockHelper.LeapYear(year);
|
|
}
|
|
|
|
/// <summary>获取指定年月的天数。</summary>
|
|
public static int MonthDays(int year, int month)
|
|
{
|
|
return ClockHelper.MonthDays(year, month);
|
|
}
|
|
|
|
/// <summary>尝试获取 DateTime 对象。</summary>
|
|
public static DateTime GetDateTime(Object datetime)
|
|
{
|
|
return ClockHelper.Resolve(datetime);
|
|
}
|
|
|
|
/// <summary>尝试获取 DateTime 对象。</summary>
|
|
public static DateTime GetDateTime(string datetime)
|
|
{
|
|
return ClockHelper.Resolve(datetime);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|