Convert Filetime to time (from variable) PHP

2.1k views Asked by At

I have a filetime time of '131841804730412861' I do not have a file, I have a filetime coming from an API I am trying to convert it to a "normal" time

Is there a way to decode filetime from a varible in php seeing as Microsoft Filetime has an epoch of Jan 1, 1601 and uses microseconds?

2

There are 2 answers

0
A l w a y s S u n n y On

filemtime — Gets file modification time and it returns the time the file was last modified, or FALSE on failure. The time is returned as a Unix timestamp, which is suitable for the date() function.

So, this should work for you but I've a doubt that your given string '131841804730412861' is a valid unix timestamp because too high in lenght.

date ("F d Y H:i:s.", filemtime($filename));
0
Khazul On

date(); takes format as first argument Documentation

Mainly You want to do something like:

$filename = 'somefile.txt';
if (file_exists($filename)) {
    echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}

btw. Number You gave in question is too large.