简体   繁体   English

是否有API将FILETIME格式的时间从UTC转换为本地时间?

[英]Is there an API to convert time in FILETIME format from UTC to local time?

I know that SystemTimeToTzSpecificLocalTime API can convert from UTC time to local time, but it takes time in SYSTEMTIME format. 我知道SystemTimeToTzSpecificLocalTime API可以从UTC时间转换为本地时间,但它需要SYSTEMTIME格式的时间。 I'm curious if there is an API that accepts FILETIME format instead? 我很好奇是否有接受FILETIME格式的API?

PS. PS。 I know that I can achieve this by using FileTimeToSystemTime() and then SystemTimeToFileTime(). 我知道我可以通过使用FileTimeToSystemTime()然后使用SystemTimeToFileTime()来实现这一点。 I was just trying to save two steps for converting to SYSTEMTIME and back. 我只是试图保存两个步骤来转换为SYSTEMTIME并返回。

Have a look at FileTimeToLocalFileTime() 看看FileTimeToLocalFileTime()

Converts a (UTC-based) file time to a local file time. 将(基于UTC)文件时间转换为本地文件时间。

And LocalFileTimeToFileTime() : LocalFileTimeToFileTime()

Converts a local file time to a file time based on the Coordinated Universal Time (UTC). 根据协调世界时(UTC)将本地文件时间转换为文件时间。

However, you cannot convert between a UTC FILETIME and a local FILETIME in a specified timezone. 但是,您无法在指定时FILETIME的UTC FILETIME和本地FILETIME之间进行转换。 The current timezone of the local machine is used for the conversion. 本地计算机的当前时区用于转换。 The documentation states: 文件说明:

To account for daylight saving time when converting a file time to a local time, use the following sequence of functions in place of using FileTimeToLocalFileTime: 要在将文件时间转换为本地时间时考虑夏令时,请使用以下函数序列代替使用FileTimeToLocalFileTime:
1. FileTimeToSystemTime 1. FileTimeToSystemTime
2. SystemTimeToTzSpecificLocalTime 2. SystemTimeToTzSpecificLocalTime
3. SystemTimeToFileTime 3. SystemTimeToFileTime

And

LocalFileTimeToFileTime uses the current settings for the time zone and daylight saving time. LocalFileTimeToFileTime使用时区和夏令时的当前设置。 Therefore, if it is daylight saving time, this function will take daylight saving time into account, even if the time you are converting is in standard time. 因此,如果是夏令时,此功能将考虑夏令时,即使您要转换的时间是标准时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM