Created
December 10, 2021 13:10
-
-
Save bartwttewaall/74152f4287ce6103796197d92820c2a6 to your computer and use it in GitHub Desktop.
Convert a localized date from an html5 input[type=date] into an ISO8601 datetime string
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 | |
$dateParam = $this->request->getRequiredBodyParam('date'); | |
$timezone = new \DateTimeZone($dateParam['timezone']); | |
$date = new \DateTime($dateParam['date'], $timezone); | |
// don't know why, but the date needs the offset | |
// otherwise it gets stored as the previous day | |
$date->add(new \DateInterval('PT'.$date->getOffset().'S')); | |
$element->uid = StringHelper::UUID(); | |
$element->date = $date->format(\DateTime::ISO8601); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment