Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DateTime.php
Go to the documentation of this file.
1 <?php
7 
15 class DateTime
16 {
20  const DATETIME_INTERNAL_FORMAT = 'yyyy-MM-dd HH:mm:ss';
21 
22  const DATE_INTERNAL_FORMAT = 'yyyy-MM-dd';
23 
24  const DATETIME_PHP_FORMAT = 'Y-m-d H:i:s';
25 
26  const DATE_PHP_FORMAT = 'Y-m-d';
27 
33  const YEAR_MIN_VALUE = -10000;
34 
38  const YEAR_MAX_VALUE = 10000;
39 
48  public function formatDate($date, $includeTime = true)
49  {
50  if ($date instanceof \DateTimeInterface) {
52  return $date->format($format);
53  } elseif (empty($date)) {
54  return null;
55  } elseif ($date === true) {
56  $date = (new \DateTime())->getTimestamp();
57  } elseif (!is_numeric($date)) {
58  $date = (new \DateTime($date))->getTimestamp();
59  }
60 
62  return (new \DateTime())->setTimestamp($date)->format($format);
63  }
64 
71  public function isEmptyDate($date)
72  {
73  return preg_replace('#[ 0:-]#', '', $date) === '';
74  }
75 
88  public function gmDate($format, $time)
89  {
90  return gmdate($format, $time);
91  }
92 
104  public function strToTime($timeStr)
105  {
106  return strtotime($timeStr);
107  }
108 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$format
Definition: list.phtml:12
formatDate($date, $includeTime=true)
Definition: DateTime.php:48