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.

60 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace Common.Extensions
{
/// <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 ToDateTime(this long timestamp)
{
return ToDataTime(timestamp);
}
/// <summary>
/// 将标准时间戳(秒级)转换为时间格式
/// </summary>
/// <param name="timestamp"></param>
/// <returns></returns>
public static DateTime ToDataTime(this long timestamp)
{
return ToDateTimeSecoders(timestamp);
}
}
}