Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 如何在C中将以纳秒为单位的unix时间戳转换为DateTime#_C# 4.0_Unix Timestamp - Fatal编程技术网

C# 4.0 如何在C中将以纳秒为单位的unix时间戳转换为DateTime#

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

我有一个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,System.DateTimeKind.Utc);
    dtDateTime = dtDateTime.AddSeconds( unixTimeStamp ).ToLocalTime();
    return dtDateTime;
}

除了OP接收的时间戳以纳秒为单位外。在调用
AddSeconds
之前,需要将该值除以100000000。