Last active
October 13, 2023 11:36
-
-
Save Gusase/62ee15d5f68b727707740e2fd693e49d to your computer and use it in GitHub Desktop.
unix epoch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ref: https://stackoverflow.com/questions/557959/ | |
$mils = round(microtime(true) * 1000); | |
$sec = ceil($mils / 1000); | |
echo date("D M d Y H:i:s",$sec); | |
echo " ---> "; | |
echo $mils; | |
// | |
function currentLocale(): float | |
{ | |
return round(microtime(true) * 1000); | |
} | |
echo currentLocale(); | |
function diffLocale(int|float $mils):string | |
{ | |
$sec = intval($mils / 1000); | |
return date("Y-m-d H:i:s",$sec); | |
} | |
echo diffLocale(1697194230997); | |
// | |
// ref: https://stackoverflow.com/q/52602031 | |
function convertDateTime($date, $format = 'Y-m-d H:i:s') | |
{ | |
$tz1 = 'UTC'; | |
$tz2 = 'Asia/Jakarta'; // UTC +7 | |
$d = new DateTime($date, new DateTimeZone($tz1)); | |
$d->setTimeZone(new DateTimeZone($tz2)); | |
return $d->format($format); | |
} | |
$utcDateTime = diffLocale(1697196749233); | |
echo convertDateTime($utcDateTime); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment