Skip to content

Instantly share code, notes, and snippets.

@abdes-zakari
Last active May 17, 2021 15:33
Show Gist options
  • Save abdes-zakari/2d44b8a0cd62681ee25c3043da97f01b to your computer and use it in GitHub Desktop.
Save abdes-zakari/2d44b8a0cd62681ee25c3043da97f01b to your computer and use it in GitHub Desktop.
PHP: Convert Windows Filetime to Date(UnixTime)
<?php
// Windows Filetime: a time value is simply a counter of ticks since an defined start of time, called epoch. Not only the "epoch date" differs between various systems, but also the counter resolution, that is how often it is updated.
// Windows uses in most functions the FILETIME structure, which represents the actual time as the number of 100-nanosecond intervals since January 1, 1601 (UTC).
# Example:
// 13228475598575215 microseconds from 1601-01-01T00:00:00Z => convert it to seconds = 13228475598575215/1000000 = 13228475598.575 seconds
// 11644473600 seconds between 1601-01-01T00:00:00Z and 1970-01-01T00:00:00Z
function convertToDate($microseconds){
$secondsFrom1601 = $microseconds/1000000;
$secondsBetween1601_1970 = 11644473600;
$unix_timestamp = $secondsFrom1601-$secondsBetween1601_1970;
return date('d-m-Y H:i:s', $unix_timestamp);
}
echo convertToDate(13228475598575215);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment