SetLocalTime function (sysinfoapi.h)

Sets the current local time and date.

Syntax

BOOL SetLocalTime(
  [in] const SYSTEMTIME *lpSystemTime
);

Parameters

[in] lpSystemTime

A pointer to a SYSTEMTIME structure that contains the new local date and time.

The wDayOfWeek member of the SYSTEMTIME structure is ignored.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The calling process must have the SE_SYSTEMTIME_NAME privilege. This privilege is disabled by default. The SetLocalTime function enables the SE_SYSTEMTIME_NAME privilege before changing the local time and disables the privilege before returning. For more information, see Running with Special Privileges.

The system uses UTC internally. Therefore, when you call SetLocalTime, the system uses the current time zone information to perform the conversion, including the daylight saving time setting. Note that the system uses the daylight saving time setting of the current time, not the new time you are setting. Therefore, to ensure the correct result, call SetLocalTime a second time, now that the first call has updated the daylight saving time setting.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header sysinfoapi.h (include Windows.h)
Library Kernel32.lib
DLL Kernel32.dll

See also

GetLocalTime

GetSystemTime

Local Time

SYSTEMTIME

SetSystemTimeAdjustment

Time Functions