1.将Unix时间戳转换为DateTime类型时间
public static System.DateTime ConvertIntDateTime(long d)
{
System.DateTime time = System.DateTime.MinValue;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
time = startTime.AddSeconds(d);
return time;
}
2.将c# DateTime时间格式转换为Unix时间戳格式
public static long ConvertDateTimeToInt(System.DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
//long t = (time.Ticks - startTime.Ticks) / 10000; //除10000调整为13位
long t = (time.Ticks - startTime.Ticks) / 10000000; //除10000000调整为10位
return t;
}
3.Mysql 时间转化
1.10位数字转时间
select from_unixtime("1669824447")
2.时间转10位数字
select unix_timestamp("2022-12-1 11:02:56")
标签:10,C#,Ticks,System,long,DateTime,startTime,time From: https://www.cnblogs.com/liaoweiyang/p/16986945.html