具有实际日期的ToFileTime转换错误 [英] ToFileTime conversion error with actual date

查看:103
本文介绍了具有实际日期的ToFileTime转换错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我只是转换了DateTime.Now.Date.ToFileTime()但从FileTime转换回datetime时,它提供了一些不同的datetime.

请帮助我解决此问题,我必须为我的美国客户进行转换(EST时区)

以下是将FileTime值转换为实际日期时间时的美国时间,它表示小时数有所不同.

Hi,

i just converted DateTime.Now.Date.ToFileTime() but when converting back to datetime from FileTime it gives some different datetime.

Please help me to fix this issue,i have to do this conversion for my US client (EST timezone)

Below is the time of US when converting FileTime value to actual datetime it gives some difference in hours.

08/18/2015 09:55:02
FileTime :  130843440000000000




谢谢
Jeetendra




Thanks
Jeetendra

推荐答案

您没有获得相同的返回时间,因为您已经通过调用DateTime.Now.Date删除了时间部分.

Date属性 [ ^ ]返回与该实例具有相同日期的新对象,并且时间值设置为午夜12:00:00(00:00:00)."

( NB:因为您是在EST时区在计算机上运行此程序,因此实际上相当于格林尼治标准时间凌晨4点.)

如果要包括时间,请不要使用Date属性:
You''re not getting the same time back because you''ve stripped out the time part by calling DateTime.Now.Date.

The Date property[^] returns "a new object with the same date as this instance, and the time value set to 12:00:00 midnight (00:00:00)."

(NB: Because you''re running this on a computer in the EST timezone, this will actually be equivalent to 4 AM UTC.)

If you want to include the time, then don''t use the Date property:
long fileTime = DateTime.Now.ToFileTime();
DateTime theTime = DateTime.FromFileTime(fileTime);


这篇关于具有实际日期的ToFileTime转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆