| 1 |
<?php |
| 2 |
namespace Averta\Core\Utility; |
| 3 |
|
| 4 |
class Date { |
| 5 |
|
| 6 |
/** |
| 7 |
* Converts one date time format to another format |
| 8 |
* |
| 9 |
* @param string $dateTime |
| 10 |
* @param string $toFormat |
| 11 |
* @param string $fromFormat |
| 12 |
* @param string $timeZone |
| 13 |
* |
| 14 |
* @return string |
| 15 |
*/ |
| 16 |
public static function covertDateFormat( $dateTime, $toFormat = 'M d, Y H:i:s', $fromFormat = 'Y-m-d H:i:s', $timeZone = 'UTC' ){ |
| 17 |
$dateTimeClass = \DateTime::createFromFormat( |
| 18 |
$fromFormat, |
| 19 |
$dateTime, |
| 20 |
new \DateTimeZone( $timeZone ) |
| 21 |
); |
| 22 |
|
| 23 |
if ( $dateTimeClass === false ) { |
| 24 |
return $dateTime; |
| 25 |
} |
| 26 |
|
| 27 |
return $dateTimeClass->format( $toFormat ); |
| 28 |
} |
| 29 |
} |
| 30 |
|