Edit in GitHubLog an issue
Thanks to Rakesh Jesadiya for contributing this topic!

DateTime library

The DateTime library provides utilities to work with date and time formatting. Provided methods in this library are described below.

Usage

MethodDescription
formatDate
Format the date to the internal format
isEmptyDate
Check whether provided date value is empty or null

Example

The following example shows how to format the current date and time into the internal format.

Copied to your clipboard
<?php
use Magento\Framework\Stdlib\DateTime;
...
/**
* @var DateTime
*/
private $dateTime;
/**
* SomeClass constructor.
*
* @param DateTime $dateTime
*/
public function __construct(DateTime $dateTime)
{
$this->dateTime = $dateTime;
}
/**
* display current date to internal format time zone
*
* @return string
*/
public function getFormatDate(): string
{
return $this->dateTime->formatDate(time());
}
...
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.