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 | |
| $currentDateTime = new DateTime(); | |
| echo $currentDateTime->format('d-m-Y H:i:s'); |
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 | |
| $currentDateTime = new DateTime(); | |
| //COOKIE: l, d-M-Y H:i:s T | |
| echo $currentDateTime->format(DateTime::COOKIE) . PHP_EOL; | |
| //RSS: D, d M Y H:i:s O | |
| echo $currentDateTime->format(DateTime::RSS) . PHP_EOL; |
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 | |
| $currentDateTime = new DateTime(); | |
| $myFormat = 'Y-m-d H:i:s'; | |
| $myFormat2 = 'd-m-Y H:i:s'; | |
| $myFormat3 = 'd-m-Y'; | |
| echo $currentDateTime->format($myFormat) . PHP_EOL; |
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 | |
| $myDateTime = new DateTime('2000-10-12 09:01:10'); | |
| echo $myDateTime->format('d-m-Y') . PHP_EOL;//12-10-2000 | |
| echo $myDateTime->format('d-m-Y H:i:s');//12-10-2000 09:01:10 |
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 | |
| $now = new DateTime('now');//Valor padrão | |
| $today = new DateTime('today'); | |
| $yesterday = new DateTime('yesterday'); | |
| $tomorrow = new DateTime('tomorrow'); | |
| echo 'Now: ' . $now->format('d-m-Y H:i:m') . PHP_EOL; | |
| echo 'Today: ' . $today->format('d-m-Y H:i:m') . PHP_EOL; | |
| echo 'Yesterday: ' . $yesterday->format('d-m-Y H:i:m') . PHP_EOL; |
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 | |
| $myDate1 = new DateTime('+ 3 days'); | |
| $myDate2 = new DateTime('- 1 week'); | |
| $myDate3 = new DateTime('+ 2 months'); | |
| $myDate4 = new DateTime('+ 10 years'); | |
| echo $myDate1->format('d/m/Y H:i:s') . PHP_EOL; | |
| echo $myDate2->format('d/m/Y H:i:s') . PHP_EOL; | |
| echo $myDate3->format('d/m/Y H:i:s') . PHP_EOL; |
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 | |
| $timeZone1 = new DateTimeZone('Asia/Dubai'); | |
| $timeZone2 = new DateTimeZone('America/New_York'); | |
| $timeZone3 = new DateTimeZone('America/Sao_Paulo'); | |
| $date1 = new DateTime('now', $timeZone1); | |
| $date2 = new DateTime('now', $timeZone2); | |
| $date3 = new DateTime('now', $timeZone3); |
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 | |
| $now = new DateTime(); | |
| $today = new DateTime('today'); | |
| $yesterday = new DateTime('yesterday'); | |
| $tomorrow = new DateTime('tomorrow'); | |
| if ($now >= $today) { | |
| echo $now->format('d/m/Y H:i:s') . ' it greater ' . $today->format('d/m/Y H:i:s') . PHP_EOL; | |
| } |
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 | |
| $dateTime1 = new DateTime('2016-12-01 12:10:15'); | |
| $dateTime2 = new DateTime('2017-01-08 08:18:09'); | |
| $dateInterval = $dateTime1->diff($dateTime2); | |
| print_r($dateInterval); |
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 | |
| $dateTime = new DateTime('2016-12-01 00:00:01'); | |
| echo $dateTime->format('d/m/Y H:i:s') . PHP_EOL; | |
| //Adicionado 40 dias a nossa data | |
| $dateTime->add(new DateInterval('P40D')); | |
| echo $dateTime->format('d/m/Y H:i:s'); |