Skip to content

Instantly share code, notes, and snippets.

@piotr-zuralski
Created October 24, 2020 20:40
Show Gist options
  • Save piotr-zuralski/0c82bcdfd9130d058f5311ce85199109 to your computer and use it in GitHub Desktop.
Save piotr-zuralski/0c82bcdfd9130d058f5311ce85199109 to your computer and use it in GitHub Desktop.
PHP DateTime with mictotime
<?php
declare(strict_types=1);
$t = explode(' ', microtime());
$dateTime = DateTime::createFromFormat('U.u',
$t[1] . substr($t[0], 1, 7)
);
$dateTime->setTimeZone(
new DateTimeZone(
date_default_timezone_get() ?: 'UTC'
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment