using Apewer.Internals;
using System;
using System.Collections.Generic;
using System.Text;
namespace Apewer
{
/// 时钟。
public class ClockUtility
{
/// 表示当前时钟的文本,显示为易于阅读的格式。
public static string Lucid
{
get { return ClockValue.Current.Lucid; }
}
/// 表示当前时钟的文本,显示为连续的数字。
public static string Compact
{
get { return ClockValue.Current.Compact; }
}
/// 获取当前本地时间以秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。
public static long SecondStamp()
{
return ClockHelper.Stamp(new DateTime(1970, 1, 1, 0, 0, 0, 0), false);
}
/// 获取指定时间以秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。
public static long SecondStamp(DateTime datetime)
{
return ClockHelper.Stamp(datetime, false);
}
/// 获取当前本地时间以毫秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。
public static long MilliSecondStamp()
{
return ClockHelper.Stamp(new DateTime(1970, 1, 1, 0, 0, 0, 0), true);
}
/// 获取指定时间以毫秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。
public static long MilliSecondStamp(DateTime datetime)
{
return ClockHelper.Stamp(datetime, true);
}
/// 获取 UTC 时间。
public static DateTime UtcDateTime
{
get { return DateTime.UtcNow; }
}
/// 获取 UTC 时间以秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。
public static long UtcSecondStamp
{
get { return ClockHelper.Stamp(DateTime.UtcNow, false); }
}
/// 获取 UTC 时间以毫秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。
public static long UtcMilliSecondStamp
{
get { return ClockHelper.Stamp(DateTime.UtcNow, true); }
}
/// 获取本地时间。
public static DateTime LocalDateTime
{
get { return DateTime.Now; }
}
/// 获取本地时间以秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。
public static long LocalSecondStamp
{
get { return ClockHelper.Stamp(DateTime.Now, false); }
}
/// 获取本地时间以毫秒为单位的时间戳,以 1970-01-01 00:00:00.000 为原点。
public static long LocalMilliSecondStamp
{
get { return ClockHelper.Stamp(DateTime.Now, true); }
}
/// 转换毫秒时间戳到易于阅读的文本。
public static string ToLucid(long stamp)
{
return ClockValue.Create(stamp).Lucid;
}
/// 转换 DateTime 对象到易于阅读的文本。
public static string ToLucid(DateTime datetime)
{
return ClockValue.Create(datetime).Lucid;
}
/// 转换 DateTime 对象到易于阅读的文本。
public static string ToLucidDate(DateTime datetime)
{
return ClockValue.Create(datetime).LucidDate;
}
/// 转换 DateTime 对象到易于阅读的文本。
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;
}
/// 转换毫秒时间戳到紧凑文本。
public static string ToCompact(long stamp)
{
return ClockValue.Create(stamp).Compact;
}
/// 转换 DateTime 对象到紧凑文本。
public static string ToCompact(DateTime datetime)
{
return ClockValue.Create(datetime).Compact;
}
/// 判断闰年。
public static bool LeapYear(int year)
{
return ClockHelper.LeapYear(year);
}
/// 获取指定年月的天数。
public static int MonthDays(int year, int month)
{
return ClockHelper.MonthDays(year, month);
}
/// 尝试获取 DateTime 对象。
public static DateTime GetDateTime(Object datetime)
{
return ClockHelper.Resolve(datetime);
}
/// 尝试获取 DateTime 对象。
public static DateTime GetDateTime(string datetime)
{
return ClockHelper.Resolve(datetime);
}
}
}