是否有将 FILETIME 格式的时间从 UTC 转换为本地时间的 API? [英] Is there an API to convert time in FILETIME format from UTC to local time?

查看:26
本文介绍了是否有将 FILETIME 格式的时间从 UTC 转换为本地时间的 API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道SystemTimeToTzSpecificLocalTime API 可以将UTC 时间转换为本地时间,但SYSTEMTIME 格式需要时间.我很好奇是否有接受 FILETIME 格式的 API?

I know that SystemTimeToTzSpecificLocalTime API can convert from UTC time to local time, but it takes time in SYSTEMTIME format. I'm curious if there is an API that accepts FILETIME format instead?

附注.我知道我可以通过使用 FileTimeToSystemTime() 和 SystemTimeToFileTime() 来实现这一点.我只是想节省两个步骤来转换为 SYSTEMTIME 并返回.

PS. I know that I can achieve this by using FileTimeToSystemTime() and then SystemTimeToFileTime(). I was just trying to save two steps for converting to SYSTEMTIME and back.

推荐答案

查看 FileTimeToLocalFileTime()

将(基于 UTC 的)文件时间转换为本地文件时间.

Converts a (UTC-based) file time to a local file time.

LocalFileTimeToFileTime():

将本地文件时间转换为基于协调世界时 (UTC) 的文件时间.

Converts a local file time to a file time based on the Coordinated Universal Time (UTC).

但是,您无法在指定时区的 UTC FILETIME 和本地 FILETIME 之间进行转换.本地机器的当前时区用于转换.文档指出:

However, you cannot convert between a UTC FILETIME and a local FILETIME in a specified timezone. The current timezone of the local machine is used for the conversion. The documentation states:

要在将文件时间转换为本地时间时考虑夏令时,请使用以下函数序列代替 FileTimeToLocalFileTime:
1. 文件时间到系统时间
2. SystemTimeToTzSpecificLocalTime
3.系统时间到文件时间

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:
1. FileTimeToSystemTime
2. SystemTimeToTzSpecificLocalTime
3. SystemTimeToFileTime

LocalFileTimeToFileTime 使用时区和夏令时的当前设置.因此,如果是夏令时,即使您转换的时间是标准时间,此功能也会考虑夏令时.

LocalFileTimeToFileTime uses the current settings for the time zone and daylight saving time. 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.

这篇关于是否有将 FILETIME 格式的时间从 UTC 转换为本地时间的 API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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