Edit

Share via


SystemClock.SetSystemTimeUtc(DateTime) Method

Definition

Set the system time to the given date/time. The time must be given in utc. The method requires elevated permissions. On Windows, the calling user must either be administrator or the right "Change the system clock" must have been granted to the "Users" group (in Security policy management). On Unix and MacOs, the current user must be root or the "date" command must have the setUid bit set.

public static void SetSystemTimeUtc (DateTime dt);
static member SetSystemTimeUtc : DateTime -> unit
Public Shared Sub SetSystemTimeUtc (dt As DateTime)

Parameters

dt
DateTime

Date/time to set the system clock to. This must be in UTC

Exceptions

This method is not supported on this platform

There was an error executing a system command

The user does not have permissions to set the system clock

Remarks

This method is primarily intended for setting the system clock from an external clock source, such as a DS1307 or a GNSS source when no internet connection is available. If an internet connection is available, most operating systems will by default automatically sync the time to a network server, which might interfere with this operation. So when using this method, the clock synchronization should be disabled, or it should only be done if the time difference is large.

Applies to