SystemClock.SetSystemTimeUtc(DateTime) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for