在将FILETIME转成DataTime类型时发现有8小时偏差,请大家帮忙看一下,先谢了!private string FILETIMEtoDataTime(FILETIME time) 
{
try
{

IntPtr filetime = Marshal.AllocHGlobal( Marshal.SizeOf(typeof(FILETIME)) ); 
IntPtr systime = Marshal.AllocHGlobal( Marshal.SizeOf(typeof(SYSTEMTIME)) ); 
Marshal.StructureToPtr(time,filetime,true); 
FileTimeToSystemTime( filetime ,systime); 
SYSTEMTIME st = (SYSTEMTIME) Marshal.PtrToStructure(systime,typeof(SYSTEMTIME)); 
SYSTEMTIME st1 = (SYSTEMTIME) Marshal.PtrToStructure(filetime,typeof(SYSTEMTIME)); 
int year=int.Parse(st.wYear.ToString());
int Month=int.Parse(st.wMonth.ToString());
int day =int.Parse(st.wDay.ToString());
int Hour =int.Parse(st.wHour.ToString());
int Minut =int.Parse(st.wMinute.ToString());
int Second=int.Parse(st.wSecond.ToString());

DateTime t=new DateTime(year,Month,day,Hour,Minut,Second);
t=t.AddHours(8);
return t.ToString("yyyy-MM-dd HH:mm:ss"); 
}
catch(Exception ex)
{
string ss=ex.ToString();
return "";
}


解决方案 »

  1.   

    DateTime t=new DateTime(year,Month,day,Hour,Minut,Second); 
    t=t.AddHours(8); 
    return t.ToString("yyyy-MM-dd HH:mm:ss"); 
    这句是为了去掉偏差加上的
      

  2.   

    F:\IE\IE\IECache.cs(200): 与“System.DateTime.FromFileTimeUtc(long)”最匹配的重载方法具有一些无效参数
    改成这样也不行,无法把FILETIME 转成long类型
    return DateTime.FromFileTimeUtc((long)time); 
    :(
      

  3.   

    错了.....直接转换             long _Value = (long)FILETIME.dwHighDateTime << 32 | (long)FILETIME.dwLowDateTime;System.DateTime.FromFileTimeUtc(_Value );
      

  4.   

    long longTime=(long)(time.dwHighDateTime<<32)+time.dwLowDateTime;
      

  5.   

    zgke
    long _Value = (long)FILETIME.dwHighDateTime < < 32 | (long)FILETIME.dwLowDateTime; 
    中间加的是或“|”吗?dancingbit
    "System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。\r\n参数名: 不是有效的 Win32 FileTime。\r\n   at System.DateTime.FromFileTimeUtc(Int64 fileTime)\r\n 多谢两位了
      

  6.   

                t = t.Add(DateTime.Now - DateTime.UtcNow);直接加上UTC时间把
                
                
      

  7.   

    你的filetime是哪个
    是System.Runtime.InteropServices.ComTypes.FILETIME?还是win32下的FILETIME?
      

  8.   

    先用FileTimeToLocalFileTime,再用FileTimeToSystemTime
      

  9.   

    用C#写的,在.NET 2003 下编译的,没使VC,
    zgke
     t = t.Add(DateTime.Now - DateTime.UtcNow); 这招管用