本文介绍了难道DateTime.toFileTimeUtc实际工作?我不能出示UTC FILETIME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,无论我做什么, tofiletimeutc()总是返回相同的 toFileTime()。我需要制作一个UTC时间戳。所以,我想这个实验在PowerShell中:

I noticed that no matter what I do, tofiletimeutc() always returns the same as toFileTime(). I need to produce a UTC timestamp. So I tried this experiment in Powershell:

(get-date).tofiletime();
(get-date).touniversalTime().tofiletimeutc();
(get-date).tofiletimeutc();

和输出是:

129757574870723241
129757574870723241
129757574870723241

(所有3是相同的,本地时间戳。时区设置为太平洋)。

(All 3 are identical, local-time stamps. Time zone is set to Pacific).

(获取最新).touniversalTime()正常工作,但无论哪个对UTC功能我用,这是由于某种原因,转换回当地时间。有没有人看到到底是怎么回事?

(get-date).touniversalTime() works as expected, but no matter which "to-utc" function I use, it is for some reason converted back into local time. Does anyone see what is going on?

推荐答案

是的,它的工作,你看到的是UTC时间filetimes所有三个值。

Yes, it does work all three values you see are filetimes "in UTC".

背景:

在Windows FILETIME是定义为:一个64位的价值重估presenting的100毫微秒间隔的数量自1601年1月1日(UTC)

The Windows FILETIME is defined as: "a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC)."

两个 DateTime.ToFileTime() DateTime.ToFileTimeUtc()返回UTC为基础的价值。事实上, DateTime.ToFileTime()实现为 DateTime.ToUniversalTime()。ToFileTimeUtc()

Both DateTime.ToFileTime() and DateTime.ToFileTimeUtc() return a UTC-based value.In fact, DateTime.ToFileTime() is implemented as DateTime.ToUniversalTime().ToFileTimeUtc().

更新关于注释:

该值始终是相同的,如上面说的,你看转换为的DateTime 例如,当回和倾倒的是,在您使用哪种方法:

The value is always the same, as said above, what you "see" when converting it back to a DateTime instance and dumping that, on which method you use:

这两个回报相同的日期时间值 DateTimeKind.Utc 的DateTime 值调整到UTC。

Those two return the "same" DateTime value with DateTimeKind.Utc and the DateTime value "adjusted" to UTC.

[datetime]::FromFileTimeUtc((get-date).ToFileTime())
[datetime]::FromFileTimeUtc((get-date).ToFileTimeUtc())

这两个返回的相同的DateTime值 DateTimeKind.Local 的DateTime 值调整到本地。

Those two return the "same" DateTime value with DateTimeKind.Local and the DateTime value adjusted to local.

[datetime]::FromFileTime((get-date).ToFileTime())
[datetime]::FromFileTime((get-date).ToFileTimeUtc())

这篇关于难道DateTime.toFileTimeUtc实际工作?我不能出示UTC FILETIME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:35