在将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 "";
}
}
{
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 "";
}
}
解决方案 »
- 请高手帮我看看这个程序的错误的地方怎么改
- 【急】c#打包问题,,,在线等!!!
- 一个关于开发windows服务的问题
- webpart 和 用户控件 问题
- 为什么asp.net做的项目在不同的时间和机器上运行是出现不同的结果?
- 两问题:Marshal.StructureToPtr() 不起作用? 屏幕保护也不起作用?
- u盘插入如何触发事件?
- 在MDI定义了一个静态的DataSet,供每个子窗囗的例表框调用数据,当打开多个子窗囗时一个例表框改变,其它也会改!!
- 还是捕捉打印信息的问题?
- 能不能对同一串口,如COM1口同时用多线程进行读写操作。例如一个线程读,一个同时写。
- 如何获取打印机状态(缺纸,缺墨。。。)
- c#事件跟委托趣谈(转)
t=t.AddHours(8);
return t.ToString("yyyy-MM-dd HH:mm:ss");
这句是为了去掉偏差加上的
改成这样也不行,无法把FILETIME 转成long类型
return DateTime.FromFileTimeUtc((long)time);
:(
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 多谢两位了
是System.Runtime.InteropServices.ComTypes.FILETIME?还是win32下的FILETIME?
zgke
t = t.Add(DateTime.Now - DateTime.UtcNow); 这招管用