This file contains 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 | |
$dateString = rtrim($_POST['date'], 'Z'); | |
$date = new DateTimeImmutable("$dateString Asia/Tokyo"); | |
echo $date->setTimezone(new DateTimeZone('UTC'))->format('Y-m-d H:i:s.u'); |
This file contains 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
var date = new Date(dateString + 'T' + timeString + 'Z'); |
This file contains 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 | |
$date = new DateTimeImmutable($_POST['date']); | |
echo $date->format('Y-m-d H:i:s.u'); |
This file contains 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
var dateString = '2018-01-25'; // can be numbers concat: year + '-' + month + '-' + day | |
var timeString = '12:30'; | |
var date = new Date(dateString + 'T' + timeString); // use the `T` separator for cross-browser compatibility |
This file contains 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
var lang = 'fr'; | |
var timezone = 'Europe/Paris'; // Use timezone = null to use the browser timezone | |
moment.prototype.userFormat = function (format) { | |
if (timezone) { | |
this.tz(timezone); | |
} | |
if (lang) { | |
this.locale(lang); |
This file contains 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 | |
$date = $this | |
->tz($timezone ?: 'America/Chicago') | |
->locale($lang ?: 'en_US'); |
This file contains 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 | |
// Create a macro with user settings | |
CarbonImmutable::macro('userFormat', function ($format = null) use ($timezone, $lang) { | |
$date = $this->tz($timezone)->locale($lang); | |
if ($format) { | |
return $date->isoFormat($format); // translated formatting if custom format given | |
} | |
return $date->calendar(); // default to calendar without format | |
}); |
This file contains 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
moment('2018-05-12T23:16:46.123456Z').locale('fr').calendar() |
This file contains 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 | |
$utcString = '2018-05-12 23:16:46.123456'; | |
$date = new CarbonImmutable($utcString); | |
echo $date->tz($timezone)->locale($lang)->calendar(); |
This file contains 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 | |
$inputDateString = '2018-05-12 23:16:46.123456'; | |
$start = new CarbonImmutable($inputDateString); | |
$end = $start->modify('+2 days'); | |
echo json_encode([ | |
'title' => 'Foobar', | |
'start' => $start, | |
'end' => $end, | |
]); |