MikeF
MikeF

Reputation: 1093

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. I'm curious if there is an API that accepts FILETIME format instead?

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.

Upvotes: 2

Views: 4865

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595295

Have a look at FileTimeToLocalFileTime()

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

And LocalFileTimeToFileTime():

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

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:

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

And

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.

Upvotes: 3

Related Questions