Many systems store timestamps as a single long number, either a Unix Epoch (seconds since 1970-01-01) or a Windows FILETIME (100-nanosecond intervals since 1601-01-01). Converting these raw integers back into a human-readable "YYYY-MM-DD HH:MM:SS" format is essential for log analysis, auditing, and debugging.
In this guide, we will demonstrate how to convert a Unix Epoch timestamp to a readable date using PowerShell, and how to handle Windows FILETIME values.
Method 1: Unix Epoch to Readable Date (PowerShell Bridge)
PowerShell provides the most reliable way to convert an Epoch timestamp.
Implementation Script
@echo off
setlocal
:: Example Unix timestamp: 1703512800 (2023-12-25 14:00:00 UTC)
set "epoch=1703512800"
for /f "usebackq delims=" %%A in (`
powershell -NoProfile -Command "[DateTimeOffset]::FromUnixTimeSeconds(%epoch%).LocalDateTime.ToString('yyyy-MM-dd HH:mm:ss')"
`) do set "readable=%%A"
echo.
echo ==========================================
echo EPOCH: %epoch%
echo READABLE: %readable%
echo ==========================================
pauseMethod 2: Windows FILETIME to Readable Date
Windows sometimes stores dates as FILETIME (a 64-bit value). PowerShell can handle this conversion as well:
@echo off
setlocal
:: Example: FILETIME value
set "filetime=133479360000000000"
for /f "usebackq delims=" %%A in (`
powershell -NoProfile -Command "[DateTime]::FromFileTime(%filetime%).ToString('yyyy-MM-dd HH:mm:ss')"
`) do set "readable=%%A"
echo.
echo FILETIME: %filetime%
echo READABLE: %readable%
pauseMethod 3: WMIC DateTime to Readable Date (Pure Batch)
The wmic command returns dates in a long format like 20231225140000.000000+060. You can slice this string into a readable format:
@echo off
setlocal enabledelayedexpansion
:: Get current datetime from WMIC
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /value') do (
set "dt=%%I"
)
:: Validate that dt is not empty
if not defined dt (
echo [ERROR] Failed to retrieve system date.
pause
exit /b
)
:: Slice the string into readable format
set "readable=!dt:~0,4!-!dt:~4,2!-!dt:~6,2! !dt:~8,2!:!dt:~10,2!:!dt:~12,2!"
echo Formatted: !readable!
pauseWhy Convert Timestamps?
- Log Analysis: Server logs and event viewers often store events as Epoch timestamps. Converting them makes the data human-readable.
- Auditing: Checking when a file was last modified, a user last logged in, or a certificate was issued.
- Debugging: When comparing timestamps from different systems (Unix, Windows, databases), having them all in a readable format prevents confusion.
Important Considerations
Conclusion
Converting raw timestamps to readable dates is a critical "translation" skill for any system administrator. By leveraging PowerShell's built-in date conversion methods, you can decode any timestamp format, Epoch, FILETIME, or WMIC, into a clear, standardized output. This capability is essential for log analysis, security auditing, and cross-system date synchronization.