Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
DateTime Class Reference

Public Member Functions

 formatDate ($date, $includeTime=true)
 
 isEmptyDate ($date)
 
 gmDate ($format, $time)
 
 strToTime ($timeStr)
 

Data Fields

const DATETIME_INTERNAL_FORMAT = 'yyyy-MM-dd HH:mm:ss'
 
const DATE_INTERNAL_FORMAT = 'yyyy-MM-dd'
 
const DATETIME_PHP_FORMAT = 'Y-m-d H:i:s'
 
const DATE_PHP_FORMAT = 'Y-m-d'
 
const YEAR_MIN_VALUE = -10000
 
const YEAR_MAX_VALUE = 10000
 

Detailed Description

Converter of date formats Internal dates

@api

Since
100.0.2

Definition at line 15 of file DateTime.php.

Member Function Documentation

◆ formatDate()

formatDate (   $date,
  $includeTime = true 
)

Format date to internal format

Parameters
string | \DateTimeInterface | bool | null$date
boolean$includeTime
Returns
string|null @api

Definition at line 48 of file DateTime.php.

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  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$format
Definition: list.phtml:12

◆ gmDate()

gmDate (   $format,
  $time 
)

Wrapper for native gmdate function

Parameters
string$format
int$time
Returns
string The given time in given format
Deprecated:
See also
Use Intl library for datetime handling: http://php.net/manual/en/book.intl.php

@codeCoverageIgnore

Definition at line 88 of file DateTime.php.

89  {
90  return gmdate($format, $time);
91  }
$format
Definition: list.phtml:12

◆ isEmptyDate()

isEmptyDate (   $date)

Check whether sql date is empty

Parameters
string$date
Returns
boolean

Definition at line 71 of file DateTime.php.

72  {
73  return preg_replace('#[ 0:-]#', '', $date) === '';
74  }

◆ strToTime()

strToTime (   $timeStr)

Wrapper for native strtotime function

Parameters
string$timeStr
Returns
int
Deprecated:
See also
Use Intl library for datetime handling: http://php.net/manual/en/book.intl.php

@codeCoverageIgnore

Definition at line 104 of file DateTime.php.

105  {
106  return strtotime($timeStr);
107  }

Field Documentation

◆ DATE_INTERNAL_FORMAT

const DATE_INTERNAL_FORMAT = 'yyyy-MM-dd'

Definition at line 22 of file DateTime.php.

◆ DATE_PHP_FORMAT

const DATE_PHP_FORMAT = 'Y-m-d'

Definition at line 26 of file DateTime.php.

◆ DATETIME_INTERNAL_FORMAT

const DATETIME_INTERNAL_FORMAT = 'yyyy-MM-dd HH:mm:ss'

#+ Date format, used as default. Compatible with \DateTime

Definition at line 20 of file DateTime.php.

◆ DATETIME_PHP_FORMAT

const DATETIME_PHP_FORMAT = 'Y-m-d H:i:s'

Definition at line 24 of file DateTime.php.

◆ YEAR_MAX_VALUE

const YEAR_MAX_VALUE = 10000

Maximum allowed year value

Definition at line 38 of file DateTime.php.

◆ YEAR_MIN_VALUE

const YEAR_MIN_VALUE = -10000

#- Minimum allowed year value

Definition at line 33 of file DateTime.php.


The documentation for this class was generated from the following file: