You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb.Common/Model/LongExtension.cs

52 lines
1.6 KiB
C#

2 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DSWeb.Common
{
/// <summary>
/// long数据拓展
/// </summary>
public static class LongExtension
{
/// <summary>
/// 将毫秒时间戳转换为普通时间
/// </summary>
/// <param name="timestamp">毫秒级别的时间戳</param>
/// <returns></returns>
public static DateTime ToDateTimeMilliseconds(this long timestamp)
{
System.DateTime time = System.DateTime.MinValue;
DateTime startTime = new DateTime(1970, 1, 1, 0, 0, 0);
time = startTime.AddMilliseconds(timestamp).Add(TimeZoneInfo.Local.BaseUtcOffset);
return time;
}
/// <summary>
/// 将秒级别时间戳转换为普通时间
/// </summary>
/// <param name="timestamp">秒级别的时间戳</param>
/// <returns></returns>
public static DateTime ToDateTimeSecoders(this long timestamp)
{
DateTime time = System.DateTime.MinValue;
DateTime startTime = new DateTime(1970, 1, 1, 0, 0, 0);
time = startTime.AddSeconds(timestamp).Add(TimeZoneInfo.Local.BaseUtcOffset);
return time;
}
/// <summary>
/// 讲标准时间戳(秒级)转换为时间格式
/// </summary>
/// <param name="timestamp"></param>
/// <returns></returns>
public static DateTime ToDataTime(this long timestamp)
{
return ToDateTimeSecoders(timestamp);
}
}
}