CMD Simulator
System Informationtime

TIME Command: Display and Set System Time in Windows CMD | Guide

Master the TIME command to view and modify Windows system time. Complete guide with examples, batch scripting tips, and time management techniques.

Rojan Acharya··Updated Feb 13, 2026
Share

The TIME command is a Windows Command Prompt utility that displays the current system time and optionally allows you to change it. Run TIME /T to view the current time without prompting for changes, or run TIME alone to both display and interactively set a new time. This command provides quick time access for scripts, logs, performance measurement, and system administration tasks.

Whether you're a system administrator managing server time synchronization, a developer creating precise timestamps for logs, or an IT professional troubleshooting time-related issues, the TIME command provides instant access to system time information and modification capabilities. Script developers rely on TIME for generating timestamps, measuring script execution duration, and implementing time-dependent conditional logic.

This comprehensive guide covers TIME command syntax, all parameters and options, practical examples for viewing and setting time, real-world use cases for IT professionals and developers, troubleshooting tips for time-related issues, and frequently asked questions. By the end, you'll efficiently manage system time and incorporate time logic into your automation workflows.

What Is the TIME Command?

The TIME command is a built-in Windows command-line utility available in all Windows versions from MS-DOS through Windows 11. It displays the current system time in the format configured in Windows Regional Settings (typically HH:MM:SS AM/PM in the US or HH:MM:SS in 24-hour format) and can interactively prompt to change the time or display it non-interactively with the /T parameter.

TIME runs in Command Prompt (CMD) and batch files with identical behavior. The command requires standard user permissions to view the time but needs administrator privileges to change it. The output format varies based on your Windows Regional Settings—US systems typically show 12-hour format with AM/PM, while many international systems use 24-hour format. This locale-awareness makes TIME useful for international deployments but requires careful parsing in scripts.

Syntax

TIME [/T | time]

Parameters

ParameterDescriptionRequired
/TDisplays the current time without prompting to change itNo
timeSets the system time to the specified value (format: HH:MM:SS)No
(none)Displays current time and prompts for a new timeNo

Parameters and Options

TIME (No Parameters)

Running TIME without parameters displays the current system time and prompts you to enter a new time. Press Enter without typing anything to keep the current time unchanged. This interactive mode is useful for manual time adjustments but not suitable for batch scripts where user interaction isn't possible.

The prompt format is "Enter the new time: (HH:MM:SS)" though the exact format depends on your Regional Settings. The command accepts various time formats including HH:MM, HH:MM:SS, and HH:MM:SS.MS (with milliseconds). Invalid times (like 25:99:99) are rejected with an error message.

/T (Display Only)

The /T parameter displays the current time without prompting for changes. This non-interactive mode is essential for batch scripts, log files, and automated processes where user input isn't available or desired. The output is a single line showing the current time in your system's configured format.

Example: TIME /T outputs "14:30" (24-hour format) or "2:30 PM" (12-hour format) depending on locale. Use this in scripts to capture the current time for timestamping, logging, performance measurement, or time-based logic without triggering interactive prompts.

Setting Time Directly

You can set the system time directly by providing a time value: TIME HH:MM:SS. This requires administrator privileges and immediately changes the system time without prompting for confirmation. Use this for automated time changes in deployment scripts or testing scenarios.

Example: TIME 14:30:00 sets the system time to 2:30 PM. This bypasses the interactive prompt but requires elevated permissions. Invalid times are rejected, and the command returns an error code.

Examples

Example 1: Display Current Time Without Prompt

Scenario: You need to see the current time quickly without interactive prompts.

TIME /T

Expected Output:

14:30

Explanation: Displays the current time in your system's time format (24-hour or 12-hour with AM/PM). The /T parameter prevents the interactive prompt, making this suitable for quick checks and batch scripts.

Example 2: Display Time and Prompt for Change

Scenario: You want to see the current time and optionally change it.

TIME

Expected Output:

The current time is: 14:30:25.45
Enter the new time: (HH:MM:SS)

Explanation: Shows current time with milliseconds and waits for input. Press Enter to keep the current time, or type a new time to change it. Requires administrator privileges to actually change the time.

Example 3: Create Precise Timestamp in Log

Scenario: Your batch script needs to log actions with precise timestamps.

@ECHO OFF
ECHO [%DATE% %TIME%] Script started >> script.log
REM Script operations here
ECHO [%DATE% %TIME%] Script completed >> script.log

Expected Output (in script.log):

[Thu 02/13/2026 14:30:25.45] Script started
[Thu 02/13/2026 14:30:28.12] Script completed

Explanation: Uses %TIME% environment variable (equivalent to TIME /T but includes milliseconds) to create precise timestamps in logs. This enables performance analysis and troubleshooting.

Example 4: Set System Time (Requires Administrator)

Scenario: You need to set the system time to a specific value for testing.

TIME 14:30:00

Expected Output:

(No output if successful; error message if insufficient privileges)

Explanation: Sets the system time to 2:30 PM (14:30 in 24-hour format). Requires running CMD as administrator. Use this for testing time-dependent applications or correcting incorrect system time.

Example 5: Measure Script Execution Time

Scenario: You need to measure how long your batch script takes to execute.

@ECHO OFF
ECHO Script started at: %TIME%
SET START_TIME=%TIME%

REM Script operations here
TIMEOUT /T 5 /NOBREAK >NUL

ECHO Script completed at: %TIME%
SET END_TIME=%TIME%

REM Note: Calculating duration requires complex parsing
ECHO Start: %START_TIME%
ECHO End: %END_TIME%

Expected Output:

Script started at: 14:30:25.45
Script completed at: 14:30:30.48
Start: 14:30:25.45
End: 14:30:30.48

Explanation: Captures start and end times for performance measurement. While calculating the exact duration requires complex time arithmetic, displaying both times helps identify performance bottlenecks.

Example 6: Create Time-Based Log Filename

Scenario: Your script needs to create a log file with current time in the filename.

@ECHO OFF
SET LOGTIME=%TIME::=-%
SET LOGTIME=%LOGTIME: =0%
SET LOGFILE=log_%DATE:~-4,4%%DATE:~-10,2%%DATE:~-7,2%_%LOGTIME:~0,8%.txt
ECHO Creating log: %LOGFILE%
ECHO Script execution log > %LOGFILE%

Expected Output:

Creating log: log_20260213_14-30-25.txt

Explanation: Parses TIME to create a filename-safe timestamp (replacing colons with hyphens). This enables time-based log organization and prevents filename conflicts for scripts that run multiple times per day.

Example 7: Check if Current Time is Within Business Hours

Scenario: Your script should only run during business hours (9 AM - 5 PM).

@ECHO OFF
FOR /F "tokens=1-2 delims=:" %%a IN ('TIME /T') DO SET HOUR=%%a

IF %HOUR% GEQ 9 IF %HOUR% LSS 17 (
    ECHO Current time is within business hours - proceeding
    REM Business hours operations
) ELSE (
    ECHO Current time is outside business hours - exiting
    EXIT /B 1
)

Expected Output:

Current time is within business hours - proceeding

Explanation: Extracts the hour from TIME /T and checks if it's between 9 and 17 (9 AM - 5 PM). Use this pattern for time-dependent operations like sending emails only during business hours.

Example 8: Display Multiple Time Formats

Scenario: You need to display time in multiple formats for different purposes.

@ECHO OFF
ECHO Standard format: %TIME%

REM 24-hour format (HH:MM:SS)
FOR /F "tokens=1-3 delims=:." %%a IN ("%TIME%") DO (
    ECHO 24-hour format: %%a:%%b:%%c
)

REM Compact format (HHMMSS)
FOR /F "tokens=1-3 delims=:." %%a IN ("%TIME%") DO (
    ECHO Compact format: %%a%%b%%c
)

REM Time without milliseconds
ECHO Time without ms: %TIME:~0,8%

Expected Output:

Standard format: 14:30:25.45
24-hour format: 14:30:25
Compact format: 143025
Time without ms: 14:30:25

Explanation: Demonstrates parsing and reformatting TIME output for different use cases: compact format for filenames, standard format for logs, format without milliseconds for display.

Example 9: Synchronize Time with Domain Controller

Scenario: You need to synchronize system time with the domain controller.

@ECHO OFF
ECHO Current time: %TIME%
ECHO Synchronizing with domain controller...
NET TIME \\DOMAIN-DC /SET /YES
IF %ERRORLEVEL% EQU 0 (
    ECHO Time synchronized successfully
    ECHO New time: %TIME%
) ELSE (
    ECHO Time synchronization failed
)

Expected Output:

Current time: 14:30:25.45
Synchronizing with domain controller...
Time synchronized successfully
New time: 14:30:32.78

Explanation: Uses NET TIME to synchronize with domain controller, then displays the new time. This ensures time consistency across domain-joined systems for authentication and logging.

Example 10: Create Complete Timestamp for Audit Trail

Scenario: Your script needs to create detailed audit trail entries with precise timestamps.

@ECHO OFF
SETLOCAL EnableDelayedExpansion

REM Create timestamp
SET TIMESTAMP=%DATE% %TIME%

REM Log action
ECHO ======================================== >> audit.log
ECHO Timestamp: %TIMESTAMP% >> audit.log
ECHO User: %USERNAME% >> audit.log
ECHO Computer: %COMPUTERNAME% >> audit.log
ECHO Action: System configuration change >> audit.log
ECHO ======================================== >> audit.log

ECHO Audit entry created with timestamp: %TIMESTAMP%

Expected Output:

Audit entry created with timestamp: Thu 02/13/2026 14:30:25.45

Explanation: Combines DATE and TIME for complete timestamps in audit logs. This creates comprehensive audit trails for compliance, troubleshooting, and security monitoring.

Common Use Cases

1. Precise Log Timestamping

Batch scripts use TIME to create precise timestamps in log files, including milliseconds for performance analysis, troubleshooting timing issues, and creating detailed audit trails for compliance and security monitoring.

2. Script Performance Measurement

Developers use TIME to measure script execution duration by capturing start and end times, identifying performance bottlenecks, optimizing slow operations, and documenting script performance for capacity planning.

3. Time-Based Conditional Logic

Scripts use TIME to implement time-dependent operations: running backups only during off-hours, sending notifications only during business hours, or executing maintenance tasks during low-usage periods.

4. Audit Trail and Compliance Logging

System administration scripts use TIME to timestamp all actions in audit logs, creating compliance records that document exactly when changes were made for regulatory audits and security investigations.

5. Time-Based File Naming

Automation scripts use TIME to create unique filenames with timestamps, preventing file conflicts when scripts run multiple times per day and enabling chronological file organization.

6. System Time Verification Before Critical Operations

Installation and deployment scripts use TIME to verify system time is reasonable before proceeding, preventing issues caused by incorrect system clocks that affect certificate validation, license checks, and time-based encryption.

7. Scheduled Task Time Validation

Maintenance scripts use TIME to verify they're running at the expected time, detecting scheduling issues, time zone problems, or daylight saving time transitions that could cause tasks to run at wrong times.

8. Performance Benchmarking

Quality assurance teams use TIME to benchmark operation performance, measuring how long specific tasks take and comparing performance across different systems or Windows versions.

9. Time Synchronization Verification

System administrators use TIME before and after time sync operations to verify synchronization succeeded and systems maintain accurate time for authentication, logging, and distributed system coordination.

10. Real-Time Process Monitoring

Monitoring scripts use TIME to timestamp process checks, resource measurements, and system health indicators, creating time-series data for trend analysis and capacity planning.

11. Temporary File Cleanup Based on Time

Cleanup scripts use TIME to determine if temporary files should be deleted based on creation time, implementing retention policies that delete files older than specific durations.

12. Change Management Documentation

Change management scripts use TIME to timestamp configuration snapshots, creating before/after records with precise timing for rollback planning, change verification, and compliance documentation.

Tips and Best Practices

1. Always Use /T in Batch Scripts

Use TIME /T instead of TIME in batch scripts to prevent interactive prompts that would cause scripts to hang waiting for user input. The /T parameter ensures non-interactive operation.

2. Use %TIME% Environment Variable for Milliseconds

The %TIME% environment variable includes milliseconds (HH:MM:SS.MS) while TIME /T typically shows only HH:MM. Use %TIME% for precise timestamps and performance measurement.

3. Account for Regional Time Format Differences

TIME output format varies by Regional Settings (12-hour with AM/PM vs. 24-hour format). Test scripts on systems with different locales or use PowerShell's Get-Date for consistent formatting.

4. Require Administrator Privileges for Time Changes

Changing system time requires administrator privileges. Always run CMD as administrator when scripts need to modify the time, and include error handling for access denied errors.

5. Use PowerShell for Complex Time Operations

For time arithmetic, comparisons, and formatting, use PowerShell's Get-Date cmdlet which provides rich DateTime objects with built-in methods. TIME is best for simple display and basic parsing.

6. Handle Leading Spaces in Hour Values

%TIME% includes a leading space for single-digit hours (e.g., " 9:30:25"). Replace spaces with zeros for consistent formatting: SET TIME=%TIME: =0%.

7. Sanitize TIME for Filenames

TIME output includes colons which are invalid in filenames. Replace colons with hyphens: SET FILETIME=%TIME::=-% before using in filenames.

8. Combine TIME with DATE for Complete Timestamps

Use both %DATE% and %TIME% for complete timestamps: ECHO %DATE% %TIME% - Action completed. This provides precise timing for troubleshooting and audit trails.

9. Use w32tm for Reliable Time Synchronization

Instead of manually setting time, use Windows Time service: w32tm /resync to synchronize with configured time sources. This ensures accurate, network-synchronized time.

10. Test Time Parsing on Multiple Windows Versions

TIME output format can vary slightly between Windows versions and locale settings. Test time parsing logic on all target Windows versions to ensure compatibility.

11. Use WMIC for Locale-Independent Time

For scripts that must work across all locales, use WMIC OS GET LocalDateTime which returns date/time in YYYYMMDDHHMMSS format regardless of Regional Settings.

12. Document Time Zone Assumptions

When logging times, document the time zone (local vs. UTC). For distributed systems, consider logging in UTC: use PowerShell's (Get-Date).ToUniversalTime() for UTC timestamps.

Troubleshooting Common Issues

Issue 1: "A required privilege is not held by the client" When Setting Time

Problem: Running TIME 14:30:00 returns "A required privilege is not held by the client" error.

Cause: Changing system time requires administrator privileges. Running TIME in a standard (non-elevated) Command Prompt cannot modify the time.

Solution: Right-click Command Prompt and select "Run as administrator" before executing TIME commands that change the time. Viewing the time with TIME /T doesn't require elevation.

Prevention: Always run CMD as administrator when scripts need to modify system time. Include privilege checks in scripts: NET SESSION >NUL 2>&1 returns error if not elevated.


Issue 2: Time Format Differs on Different Systems

Problem: Batch script time parsing works on your system but fails on other systems with different Regional Settings.

Cause: TIME output format depends on Windows Regional Settings. Some systems show 12-hour format with AM/PM, others show 24-hour format, and delimiter characters may vary.

Solution: Use locale-independent time retrieval: WMIC OS GET LocalDateTime returns YYYYMMDDHHMMSS format regardless of locale. Or use PowerShell: Get-Date -Format "HH:mm:ss".

Prevention: Test scripts on systems with different Regional Settings. Document time format assumptions and consider using WMIC or PowerShell for consistent time formatting.


Issue 3: TIME Command Hangs in Batch Script

Problem: Batch script stops executing when it reaches the TIME command and appears to hang.

Cause: Using TIME without /T parameter triggers an interactive prompt waiting for user input, which never comes in automated scripts.

Solution: Always use TIME /T in batch scripts to prevent interactive prompts. Replace all instances of TIME with TIME /T in automated scripts, or use %TIME% environment variable.

Prevention: Use TIME /T or %TIME% environment variable in scripts. Reserve TIME without parameters for interactive command-line use only.


Issue 4: Leading Space in Hour Causes Parsing Issues

Problem: Parsing TIME output fails for single-digit hours because of leading space (e.g., " 9:30:25" instead of "09:30:25").

Cause: Windows formats single-digit hours with a leading space instead of a leading zero in the %TIME% variable.

Solution: Replace leading spaces with zeros before parsing: SET TIME=%TIME: =0%. This ensures consistent two-digit hour format.

Prevention: Always sanitize %TIME% before parsing: replace spaces with zeros and test with both single-digit and double-digit hours.


Issue 5: Time Change Doesn't Persist After Reboot

Problem: Manually set time reverts to incorrect value after system reboot.

Cause: System is configured to sync time with a time server (domain controller, NTP server) that has incorrect time, or CMOS battery is failing and BIOS time is wrong.

Solution: For domain computers, verify domain controller time is correct. For workgroup computers, check Windows Time service configuration: w32tm /query /status. Replace CMOS battery if BIOS time resets.

Prevention: Configure proper time synchronization with reliable time sources. For domain computers, ensure domain controllers sync with external NTP servers. Monitor time drift with automated scripts.


Issue 6: Cannot Calculate Time Duration Accurately

Problem: Subtracting start time from end time in batch scripts produces incorrect results or fails completely.

Cause: Time arithmetic is complex due to 60-second minutes, 60-minute hours, and midnight rollover. Simple subtraction doesn't work.

Solution: Use PowerShell for time arithmetic: $duration = (Get-Date) - $startTime; $duration.TotalSeconds. Or convert times to seconds since midnight before subtracting.

Prevention: Use PowerShell's DateTime objects for any time calculations. Batch script time arithmetic is error-prone and should be avoided for production scripts.

Frequently Asked Questions

What is the difference between TIME and %TIME%?

TIME /T is a command that executes and returns the current time, while %TIME% is an environment variable that contains the time value including milliseconds. %TIME% is faster and includes more precision (milliseconds), making it better for most scripting uses.

How do I change the time format displayed by TIME?

TIME format is controlled by Windows Regional Settings (Control Panel → Region → Formats). Change the "Short time" format to modify TIME output. Alternatively, use PowerShell's Get-Date -Format "HH:mm:ss" for custom formatting without changing system settings.

Can I use TIME to calculate elapsed time?

TIME can capture start and end times, but calculating the duration requires complex parsing and arithmetic. Use PowerShell instead: $start = Get-Date; <operations>; $duration = (Get-Date) - $start; $duration.TotalSeconds.

Why does TIME show a leading space for single-digit hours?

Windows formats single-digit hours with a leading space (e.g., " 9:30") instead of a leading zero. Replace spaces with zeros for consistent formatting: SET TIME=%TIME: =0%.

How do I set both date and time in a batch script?

Use both DATE and TIME commands: DATE 12-25-2026 & TIME 14:30:00. Both require administrator privileges. For automated scripts, run CMD as administrator.

Can TIME set milliseconds?

Yes, TIME accepts milliseconds: TIME 14:30:25.50 sets time to 2:30 PM and 25.50 seconds. However, millisecond precision may not be maintained due to system timer resolution.

How do I get the time in HH:MM:SS format without milliseconds?

Use substring extraction: SET TIME_NO_MS=%TIME:~0,8% extracts first 8 characters (HH:MM:SS). Or use PowerShell: Get-Date -Format "HH:mm:ss".

Why does my batch script show the wrong time?

Check your system's Regional Settings—TIME output format depends on locale. Also verify system time is correct: TIME /T shows current system time, which may be wrong if time sync is broken or CMOS battery is failing.

Can I use TIME to check if it's currently nighttime?

Yes, extract the hour and check if it's outside business hours: FOR /F "tokens=1 delims=:" %%a IN ('TIME /T') DO IF %%a LSS 6 ECHO Nighttime. Or use PowerShell: (Get-Date).Hour for cleaner logic.

How do I synchronize time across multiple computers?

For domain computers, ensure all systems sync with domain controllers: w32tm /resync. For workgroup computers, configure Windows Time service to sync with external NTP servers: w32tm /config /manualpeerlist:pool.ntp.org /syncfromflags:manual /update.

Does TIME work in PowerShell?

Yes, but PowerShell users typically use Get-Date cmdlet which provides richer functionality. TIME works in PowerShell but returns a string, while Get-Date returns a DateTime object with methods and properties.

How do I create filenames with current time?

Sanitize TIME by replacing colons: SET FILETIME=%TIME::=-% then use in filename: SET FILENAME=log_%FILETIME:~0,8%.txt. This creates names like log_14-30-25.txt.

Related Commands

DATE

Displays or sets the system date. Use alongside TIME for complete date/time management. DATE /T displays date without prompting, DATE MM-DD-YYYY sets date.

When to use: Use DATE with TIME for complete timestamp creation: ECHO %DATE% %TIME%. Use DATE to set system date when TIME sets the time.

WMIC OS GET LocalDateTime

WMI command that returns date and time in YYYYMMDDHHMMSS format, independent of Regional Settings. More reliable than TIME for international scripts.

When to use: Use WMIC OS GET LocalDateTime when scripts must work across all locales without time format parsing issues. Output is consistent worldwide.

Get-Date (PowerShell)

PowerShell cmdlet that returns DateTime objects with rich formatting, arithmetic, and comparison capabilities. Far more powerful than TIME for complex time operations.

When to use: Use Get-Date in PowerShell scripts for time arithmetic, custom formatting, and time comparisons. Use TIME in CMD/batch scripts for simplicity.

w32tm (Windows Time Service)

Manages Windows Time service for time synchronization with NTP servers and domain controllers. Use to configure time sync and troubleshoot time drift.

When to use: Use w32tm /resync to force time synchronization after manually setting time, or w32tm /query /status to check time sync configuration.

NET TIME

Legacy command to display or synchronize time with network servers. Deprecated in favor of w32tm but still available for backward compatibility.

When to use: Use NET TIME \\server /SET /YES to sync time with a specific server. Prefer w32tm for modern Windows systems.

TIMEOUT

Pauses script execution for a specified number of seconds. Useful for creating delays between operations or waiting for processes to complete.

When to use: Use TIMEOUT /T 5 to pause for 5 seconds. Combine with TIME to measure elapsed time: capture TIME before and after TIMEOUT.

Quick Reference Card

CommandPurposeExample Use Case
TIME /TDisplay current timeQuick time check, scripts
TIMEDisplay and prompt to changeInteractive time setting
TIME 14:30:00Set time directlyAutomated time change
%TIME%Environment variable with timeFast time access with milliseconds
TIME /T > time.txtSave time to fileTime logging
SET TIME=%TIME: =0%Remove leading spaceConsistent time formatting
SET TIME=%TIME::=-%Sanitize for filenameTime-based filenames
ECHO %DATE% %TIME%Complete timestampLog entries, audit trails
TIME /T & DATE /TDisplay time and dateQuick system time check
w32tm /resyncSynchronize timeTime sync after manual change

Try It Yourself

Ready to master Windows time management? Practice using the TIME command in our interactive Windows Command Simulator. Experiment with time display, parsing, and build your command-line expertise in a safe, risk-free environment.

Launch the Windows Command Simulator to start practicing TIME commands now.

Want to explore more Windows commands? Check out our Complete Windows Commands Reference for detailed guides on over 200 CMD commands, including system information, file management, networking, and process control tools.

Related Guides:

Summary

The TIME command is an essential tool for Windows command-line users, providing quick access to system time information and modification capabilities. Whether you're using TIME /T for non-interactive time display in scripts or %TIME% for precise timestamps with milliseconds, this simple command delivers essential time functionality for logging, performance measurement, and time-dependent automation.

We covered TIME command syntax including the /T parameter for non-interactive display, direct time setting with TIME HH:MM:SS, and ten practical examples demonstrating time display, parsing, timestamp creation, performance measurement, and time-based conditional logic. The command works across all Windows versions but output format varies by Regional Settings, requiring careful parsing in international deployments.

Key use cases include precise log timestamping, script performance measurement, time-based conditional logic, audit trail logging, time-based file naming, system time verification, scheduled task validation, and performance benchmarking. Script developers rely on TIME for generating timestamps, measuring execution duration, and implementing time-dependent business logic.

Remember to always use TIME /T or %TIME% in batch scripts to prevent interactive prompts that would cause scripts to hang. The %TIME% variable includes milliseconds for precise timing, but requires sanitization (removing leading spaces, replacing colons) before use in filenames. Account for Regional Settings differences when parsing TIME output, or use WMIC or PowerShell for locale-independent time handling.

Practice using TIME regularly to build familiarity with time formatting and parsing techniques. The more you integrate TIME into your scripting workflows, the faster you'll create robust time-based automation, measure performance accurately, troubleshoot timing issues, and maintain comprehensive audit trails. Start with simple time display and logging, then expand to performance measurement and time-based conditional logic as your confidence grows.