Mastering Time with Shell and PowerShell

Published: February 2, 2023 | Last Modified: May 13, 2025

Tags: time shell powershell windows systeminfo wmic Win32_OperatingSystem tzutil

Categories: Shell PowerShell

Explore an array of shell and PowerShell commands focused on time management, including last boot-up time, system boot time, and time zone adjustments.

DATE

Display the current date using the DATE command:

DATE /T

wmic

LastBootUpTime

Retrieve the last boot-up time using Windows Management Instrumentation Command-line (wmic):

wmic path Win32_OperatingSystem get LastBootUpTime

SystemUpTime

Determine system uptime, showing the duration since the last boot-up:

wmic path Win32_PerfFormattedData_PerfOS_System get SystemUpTime

systeminfo

System Boot Time

Obtain the system boot time using the systeminfo command in conjunction with find:

systeminfo | find "System Boot Time"

w32tm

The w32tm command-line tool is used for diagnosing and configuring the Windows Time Service.

configuration

Check the current configuration:

w32tm /query /configuration

Register and Unregister

Register or unregister the Windows Time Service:

w32tm /unregister
w32tm /register

resync

Resynchronize the system clock with the configured time source:

w32tm /resync

query source

Display the current time source and related information:

w32tm /query /source

Win32_OperatingSystem

LastBootUpTime

Calculate the time elapsed since the last boot-up in PowerShell by subtracting the LastBootUpTime from the current date:

(get-date) - (gcim Win32_OperatingSystem).LastBootUpTime

Alternatively, execute the same command within a shell environment:

powershell.exe -c "(get-date) - (gcim Win32_OperatingSystem).LastBootUpTime"

TIME

Obtain the current system time using the TIME command with the /T flag:

TIME /T

tzutil

Display the current time zone:

Show the current time zone:

tzutil /g

Change time zone

Change the system time zone using the tzutil command by providing the desired time zone as an argument after the /s flag. For example, set the time zone to Eastern Standard Time:

tzutil /s "Eastern Standard Time"