C# 4.0 如何在C中将以纳秒为单位的unix时间戳转换为DateTime#
我有一个C#WPF用户界面和C后端。我正在从后端接收以纳秒为单位的unix时间戳。有没有办法将纳秒转换成人类可读的格式?试试这个C# 4.0 如何在C中将以纳秒为单位的unix时间戳转换为DateTime#,c#-4.0,unix-timestamp,C# 4.0,Unix Timestamp,我有一个C#WPF用户界面和C后端。我正在从后端接收以纳秒为单位的unix时间戳。有没有办法将纳秒转换成人类可读的格式?试试这个 public static DateTime UnixTimeStampToDateTime( double unixTimeStamp ) { // Unix timestamp is seconds past epoch System.DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,Syste
public static DateTime UnixTimeStampToDateTime( double unixTimeStamp )
{
// Unix timestamp is seconds past epoch
System.DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
dtDateTime = dtDateTime.AddSeconds( unixTimeStamp ).ToLocalTime();
return dtDateTime;
}
除了OP接收的时间戳以纳秒为单位外。在调用
AddSeconds
之前,需要将该值除以100000000。