Search code examples
c++-winrt

Set System Time Programmatically in uwp


Is it possible to set system Timezone, Date, and Time programmatically in uwp c++ winrt?

Based on API guideline i added

  • system management capability

  • also allowed "Change the system time" and "Change the timezone" properties for local user in Local Policies.

    <iot:Capability Name="systemManagement"/>
    

Still i see user can not change those settings in debugger. Am i doing anything wrong or this is not possible form UWP winrt?

 auto canChange = TimeZoneSettings::CanChangeTimeZone();
 if (canChange) // This is always false
 {
  TimeZoneSettings::ChangeTimeZoneByDisplayName("The zone");
 }

Solution

  • is it possible to set system Timezone, Date, and Time programmatically in uwp c++ winrt

    I'm afraid you can't set system timezone with UWP api, please refer TimeZoneSettings document remark part.

    It only available for Iot device. This API requires the use of the IoT systemManagement capability, and the inclusion of iot in the IgnorableNamespaces list.

    If you do want to set timezone within uwp, we suggest your make desktop extension for current uwp project, and set timezone with win32 api. For desktop extension, please refer to stefan's blog UWP with Desktop Extension