Created
December 18, 2012 22:17
-
-
Save vimishor/4332595 to your computer and use it in GitHub Desktop.
The clean and fast way for changing date format in PHP
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 | |
$date = new DateTime('now'); | |
echo $date->format('d/m/Y').PHP_EOL; // format: day/month/year | |
echo $date->format('m-d-Y').PHP_EOL; // format: month-day-year | |
echo $date->format('Y-m-d').PHP_EOL; // format: year-month-day | |
// add 3 days to current date and output using format year-day-month | |
echo $date->setTimestamp( strtotime('+3 days', $date->getTimestamp()) )->format('Y-d-m'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also look at the PHP INTL functions for i18n and l10n methods of displaying dates. Not everyone is American.