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.
76 lines
2.8 KiB
76 lines
2.8 KiB
namespace Znyc.CloudCar.Utility.Helper
|
|
{
|
|
public static class DateHelper
|
|
{
|
|
/// <summary>
|
|
/// 时间戳起始日期
|
|
/// </summary>
|
|
public static DateTime TimestampStart = new(1970, 1, 1, 0, 0, 0, 0);
|
|
|
|
public static DateTime StampToDateTime(string time)
|
|
{
|
|
time = time.Substring(0, 10);
|
|
double timestamp = Convert.ToInt64(time);
|
|
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
|
|
dateTime = dateTime.AddSeconds(timestamp).ToLocalTime();
|
|
return dateTime;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换为时间戳
|
|
/// </summary>
|
|
/// <param name="dateTime"></param>
|
|
/// <param name="milliseconds">是否使用毫秒</param>
|
|
/// <returns></returns>
|
|
public static int ToTimestamp(this DateTime dateTime, bool milliseconds = false)
|
|
{
|
|
TimeSpan timestamp = dateTime.ToUniversalTime() - TimestampStart;
|
|
return (int)(milliseconds ? timestamp.TotalMilliseconds : timestamp.TotalSeconds);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 出厂时间
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public static DateOutput GetAppearanceTimeAsync(long id)
|
|
{
|
|
DateOutput output = new DateOutput();
|
|
switch (id)
|
|
{
|
|
case 8001:
|
|
output.Start = new DateTime(DateTime.Now.AddYears(-3).Year, 1, 1);
|
|
output.End = new DateTime(DateTime.Now.Year, 12, 31);
|
|
break;
|
|
case 8002:
|
|
output.Start = new DateTime(DateTime.Now.AddYears(-5).Year, 1, 1);
|
|
output.End = new DateTime(DateTime.Now.AddYears(-3).Year, 12, 31);
|
|
break;
|
|
case 8003:
|
|
output.Start = new DateTime(DateTime.Now.AddYears(-8).Year, 1, 1);
|
|
output.End = new DateTime(DateTime.Now.AddYears(-5).Year, 12, 31);
|
|
break;
|
|
case 8004:
|
|
output.Start = new DateTime(DateTime.Now.AddYears(-12).Year, 1, 1);
|
|
output.End = new DateTime(DateTime.Now.AddYears(-8).Year, 12, 31);
|
|
break;
|
|
case 8005:
|
|
output.Start = DateTime.MinValue;
|
|
output.End = new DateTime(DateTime.Now.AddYears(-12).Year, 12, 31);
|
|
break;
|
|
default:
|
|
output.Start = DateTime.MinValue;
|
|
output.End = DateTime.MaxValue;
|
|
break;
|
|
}
|
|
return output;
|
|
}
|
|
|
|
public class DateOutput
|
|
{
|
|
public DateTime Start { get; set; }
|
|
|
|
public DateTime End { get; set; }
|
|
}
|
|
}
|
|
}
|
|
|