将FILETIME转换为DateTime时出错 [英] Error converting FILETIME to DateTime

查看:71
本文介绍了将FILETIME转换为DateTime时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



它应该很简单,

将FILETIME放入长期

使用DateTime.FromFileTimeUtc

帮助甚至说:将指定的Windows文件时间转换为

等效的UTC时间。

现在为什么会这样:

原始文件时间21/02/2006 00:33:29

字节:

80 C2 E6 AB

6D 36 C6 01


当我兑换它时我有:

1)20/02/2006 22:26:19

2)20/02/2006 22:26:19


代码:

Dim ad3 As System.DateTime

Dim aLn1 As Long

Dim ad1 As System.Runtime.InteropServices.ComTypes.FILETIME


ad1.dwHighDateTime =& H1C6366D

ad1.dwLowDateTime =& HABE6C280

aLn1 =(CLng(ad1.dwHighDateTime)<< 32)+ CLng(ad1.dwLowDateTime)

>
ad3 = DateTime.FromFileTimeUtc(aLn1)

Debug.Print(" 1)" &安培; ad3)

ad3.ToLocalTime()

Debug.Print(" 2)" &安培; ad3)


,如果我这样做甚至更糟:

ad3 = CDate(21/02/2006 00:33:29)


Thicks财产等于:

ad3.Ticks& H8C8049591E69280 Long

请有人可以帮助我吗?


谢谢,

M.

解决方案

msAvazzi,


你想要实现的目标是什么,在datetime有很多方法

,我没有看到你的目标是什么。我猜这对其他人来说是一样的。


通过实例
http://msdn.microsoft.com/library/de...ssaddtopic.asp


Cor


" msavazzi" <米******* @ discussion.microsoft.com> schreef in bericht

news:50 ********************************** @ microsof t.com ...


它应该很简单,使用DateTime.FromFileTimeUtc 转换日期>
帮助甚至说:将指定的Windows文件时间转换为
等效的UTC时间。

现在为什么会这样:
原始文件时间21/02/2006 00:33:29

字节:
80 C2 E6 AB
6D 36 C6 01
当我转换它时我有:
1)20/02/2006 22:26:19
2)20/02/2006 22:26:19

代码:
Dim ad3 As System.DateTime
Dim aLn1 As Long
Dim ad1 As System.Runtime.InteropServices.ComTypes.FILETIME
ad1.dwLowDateTime =& HABE6C280

aLn1 =(CLng(ad1.dwHighDateTime)<< 32)+ CLng(ad1.dwLowDateTime)

ad3 = DateTime.FromFileTimeUtc(aLn1)
De bug.Print(" 1)" &安培; ad3)
ad3.ToLocalTime()
Debug.Print(" 2)" &安培; ad3)

如果我这样做甚至更糟:
ad3 = CDate(21/02/2006 00:33:29)

Thicks属性等于:
ad3.Ticks& H8C8049591E69280长

请有人帮帮我吗?

谢谢,
M。



Cor,

我有一个FILETIME(我从文件中读取)并且我想将它存储在
$ b中$ b DateTime变量。


我同意你的意见,它有很多方法。


不幸的是它看起来像他们' 'T WORK(或者不清楚如何使用它们

工作)。

如果你尝试了我发布的代码,你会看到。


这里是MSDN参考:
http://msdn.microsoft.com/library/en...asp?frame=true


M


" Cor Ligthert [MVP]"写道:

msAvazzi,

你想要实现的是什么,在datetime有这么多方法
我没看到什么你的目标是。我猜这对其他人来说是一样的。

实例
http://msdn.microsoft.com/library/de...ssaddtopic.asp
< Cor / /
msavazzi <米******* @ discussion.microsoft.com> schreef在bericht
新闻:50 ********************************** @ microsof t.com。 ..


它应该很简单,使用DateTime.FromFileTimeUtc
将FILETIME放在一个长的
转换日期。
>帮助甚至说:将指定的Windows文件时间转换为
等效的UTC时间。

现在为什么会这样:
原始文件时间21/02/2006 00:33: 29

字节:
80 C2 E6 AB
6D 36 C6 01
当我转换它时我有:
1)20 / 02/2006 22:26:19
2)20/02/2006 22:26:19

代码:
Dim ad3 As System.DateTime
Dim aLn1 As Long
Dim ad1 As System.Runtime.InteropServices.ComTypes.FILETIME
ad1.dwLowDateTime =& HABE6C280

aLn1 =(CLng(ad1.dwHighDateTime)<< 32)+ CLng(ad1.dwLowDateTime)
ad3 = DateTime.FromFileTimeUtc(aLn1)
Debug.P rint(1) &安培; ad3)
ad3.ToLocalTime()
Debug.Print(" 2)" &安培; ad3)

如果我这样做甚至更糟:
ad3 = CDate(21/02/2006 00:33:29)

Thicks属性等于:
ad3.Ticks& H8C8049591E69280长

请有人帮帮我吗?

谢谢,
M。

<你知道吗?


/msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDateTimeClassFromFileTimeUtcTopic.asp\"target =_ blank> http://msdn.microsoft.com/library/de。 ..meUtcTopic.asp


Cor


" msavazzi" <米******* @ discussion.microsoft.com> schreef in bericht

新闻:BA ********************************** @ microsof t.com ...

Cor,
我有一个FILETIME(我从文件中读取),我想将它存储在一个
DateTime变量中。

我同意你的观点,它有很多方法。

不幸的是它看起来好像不工作(或者不清楚如何使用它们
工作)。
如果您尝试了我发布的代码,您会看到。

这里是MSDN参考:
http://msdn.microsoft.com/library/en .. .asp?frame = true

  Cor Ligthert [MVP]"写道:

msAvazzi,

你想要实现的是什么,
datetime有很多方法,我我没看到你的目标是什么。我认为
其他人也是一样。

实例
http://msdn.microsoft.com/library/de...ssaddtopic.asp <

msavazzi <米******* @ discussion.microsoft.com> schreef在bericht
新闻:50 ********************************** @ microsof t.com。 ..

>
>应该很简单,
>把FILETIME放在长的
>使用DateTime.FromFileTimeUtc将其转换为日期
>
>帮助甚至说:将指定的Windows文件时间转换为
>等效UTC时间。
>
>
>现在为什么会这样:
>原文件时间21/02/2006 00:33:29
>
>字节:
> 80 C2 E6 AB
> 6D 36 C6 01
>
>当我转换它时,我有:
> 1)20/02/2006 22:26:19
> 2)20/02/2006 22:26:19
>
>代码:
> Dim ad3 As System.DateTime
> Dim aLn1 As Long
> Dim ad1 As System.Runtime.InteropServices.ComTypes.FILETIME
>
> ad1.dwHighDateTime =& H1C6366D
> ad1.dwLowDateTime =& HABE6C280
>
> aLn1 =(CLng(ad1.dwHighDateTime)<<< 32)+
> CLng(ad1.dwLowDateTime)
>
> ad3 = DateTime.FromFileTimeUtc(aLn1)
> Debug.Print(" 1)" &安培; ad3)
> ad3.ToLocalTime()
> Debug.Print(" 2)" &安培; ad3)
>
>如果我这样做甚至更糟:
> ad3 = CDate(21/02/2006 00:33:29)
>
> Thicks属性等于:
> ad3.Ticks& H8C8049591E69280 Long
>
>
>请有人帮帮我吗?
>
>谢谢,
> M。




Hi,
it should be simple,
put FILETIME in a Long
conver it in date using the DateTime.FromFileTimeUtc

The help even says: Converts the specified Windows file time to an
equivalent UTC time.
Now why happens this:
original filetime 21/02/2006 00:33:29

bytes:
80 C2 E6 AB
6D 36 C6 01

when I convert it I have:
1) 20/02/2006 22:26:19
2) 20/02/2006 22:26:19

Code:
Dim ad3 As System.DateTime
Dim aLn1 As Long
Dim ad1 As System.Runtime.InteropServices.ComTypes.FILETIME

ad1.dwHighDateTime = &H1C6366D
ad1.dwLowDateTime = &HABE6C280

aLn1 = (CLng(ad1.dwHighDateTime) << 32) + CLng(ad1.dwLowDateTime)

ad3 = DateTime.FromFileTimeUtc(aLn1)
Debug.Print("1) " & ad3)
ad3.ToLocalTime()
Debug.Print("2) " & ad3)

and even worst if I do:
ad3 = CDate("21/02/2006 00:33:29")

the Thicks property is equal to:
ad3.Ticks &H8C8049591E69280 Long
please can anyone help me?

Thanks,
M.

解决方案

msAvazzi,

What is it what you want to achieve, there are so many methods in datetime
that I am not seeing what your goal is. I gues that is the same for others.

By instance
http://msdn.microsoft.com/library/de...ssaddtopic.asp

Cor

"msavazzi" <m.*******@discussion.microsoft.com> schreef in bericht
news:50**********************************@microsof t.com...

Hi,
it should be simple,
put FILETIME in a Long
conver it in date using the DateTime.FromFileTimeUtc

The help even says: Converts the specified Windows file time to an
equivalent UTC time.
Now why happens this:
original filetime 21/02/2006 00:33:29

bytes:
80 C2 E6 AB
6D 36 C6 01

when I convert it I have:
1) 20/02/2006 22:26:19
2) 20/02/2006 22:26:19

Code:
Dim ad3 As System.DateTime
Dim aLn1 As Long
Dim ad1 As System.Runtime.InteropServices.ComTypes.FILETIME

ad1.dwHighDateTime = &H1C6366D
ad1.dwLowDateTime = &HABE6C280

aLn1 = (CLng(ad1.dwHighDateTime) << 32) + CLng(ad1.dwLowDateTime)

ad3 = DateTime.FromFileTimeUtc(aLn1)
Debug.Print("1) " & ad3)
ad3.ToLocalTime()
Debug.Print("2) " & ad3)

and even worst if I do:
ad3 = CDate("21/02/2006 00:33:29")

the Thicks property is equal to:
ad3.Ticks &H8C8049591E69280 Long
please can anyone help me?

Thanks,
M.



Cor,
I have a FILETIME (that I read from a File) and I want to store it in a
DateTime variable.

And I do agree with you, it has a lot of methods.

Unluckily it looks like THEY DON''T WORK (or is not clear how to have them
work).
If you try the code I''ve posted you''ll see.

here is tha MSDN reference:
http://msdn.microsoft.com/library/en...asp?frame=true

M

"Cor Ligthert [MVP]" wrote:

msAvazzi,

What is it what you want to achieve, there are so many methods in datetime
that I am not seeing what your goal is. I gues that is the same for others.

By instance
http://msdn.microsoft.com/library/de...ssaddtopic.asp

Cor

"msavazzi" <m.*******@discussion.microsoft.com> schreef in bericht
news:50**********************************@microsof t.com...

Hi,
it should be simple,
put FILETIME in a Long
conver it in date using the DateTime.FromFileTimeUtc

The help even says: Converts the specified Windows file time to an
equivalent UTC time.
Now why happens this:
original filetime 21/02/2006 00:33:29

bytes:
80 C2 E6 AB
6D 36 C6 01

when I convert it I have:
1) 20/02/2006 22:26:19
2) 20/02/2006 22:26:19

Code:
Dim ad3 As System.DateTime
Dim aLn1 As Long
Dim ad1 As System.Runtime.InteropServices.ComTypes.FILETIME

ad1.dwHighDateTime = &H1C6366D
ad1.dwLowDateTime = &HABE6C280

aLn1 = (CLng(ad1.dwHighDateTime) << 32) + CLng(ad1.dwLowDateTime)

ad3 = DateTime.FromFileTimeUtc(aLn1)
Debug.Print("1) " & ad3)
ad3.ToLocalTime()
Debug.Print("2) " & ad3)

and even worst if I do:
ad3 = CDate("21/02/2006 00:33:29")

the Thicks property is equal to:
ad3.Ticks &H8C8049591E69280 Long
please can anyone help me?

Thanks,
M.




And you tried this as well?

http://msdn.microsoft.com/library/de...meUtcTopic.asp

Cor

"msavazzi" <m.*******@discussion.microsoft.com> schreef in bericht
news:BA**********************************@microsof t.com...

Cor,
I have a FILETIME (that I read from a File) and I want to store it in a
DateTime variable.

And I do agree with you, it has a lot of methods.

Unluckily it looks like THEY DON''T WORK (or is not clear how to have them
work).
If you try the code I''ve posted you''ll see.

here is tha MSDN reference:
http://msdn.microsoft.com/library/en...asp?frame=true

M

"Cor Ligthert [MVP]" wrote:

msAvazzi,

What is it what you want to achieve, there are so many methods in
datetime
that I am not seeing what your goal is. I gues that is the same for
others.

By instance
http://msdn.microsoft.com/library/de...ssaddtopic.asp

Cor

"msavazzi" <m.*******@discussion.microsoft.com> schreef in bericht
news:50**********************************@microsof t.com...

> Hi,
> it should be simple,
> put FILETIME in a Long
> conver it in date using the DateTime.FromFileTimeUtc
>
> The help even says: Converts the specified Windows file time to an
> equivalent UTC time.
>
>
> Now why happens this:
> original filetime 21/02/2006 00:33:29
>
> bytes:
> 80 C2 E6 AB
> 6D 36 C6 01
>
> when I convert it I have:
> 1) 20/02/2006 22:26:19
> 2) 20/02/2006 22:26:19
>
> Code:
> Dim ad3 As System.DateTime
> Dim aLn1 As Long
> Dim ad1 As System.Runtime.InteropServices.ComTypes.FILETIME
>
> ad1.dwHighDateTime = &H1C6366D
> ad1.dwLowDateTime = &HABE6C280
>
> aLn1 = (CLng(ad1.dwHighDateTime) << 32) +
> CLng(ad1.dwLowDateTime)
>
> ad3 = DateTime.FromFileTimeUtc(aLn1)
> Debug.Print("1) " & ad3)
> ad3.ToLocalTime()
> Debug.Print("2) " & ad3)
>
> and even worst if I do:
> ad3 = CDate("21/02/2006 00:33:29")
>
> the Thicks property is equal to:
> ad3.Ticks &H8C8049591E69280 Long
>
>
> please can anyone help me?
>
> Thanks,
> M.




这篇关于将FILETIME转换为DateTime时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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