lang/php/ PhpDateTime


Get unix timestamp with time()

php > echo time();
1678298613

Get formatted date via date() (see docs) and note warning about timezones.

Get formatted UTC time via gmdate() (see docs)

php > echo gmdate("Y-m-d H-i-s"); # W for week of year, w for day of week
2023-03-08 18-03-05

Get nicely formatted date/time. This is the more modern approach.

php > $date_utc = new \DateTime("now", new \DateTimeZone("UTC"));
php > echo $date_utc->format(\DateTime::RFC850);
Wednesday, 08-Mar-23 18:04:00 UTC