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
formatDateFormat the date to the internal format
isEmptyDateCheck 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
1<?php
2
3use Magento\Framework\Stdlib\DateTime;
4
5...
6 /**
7 * @var DateTime
8 */
9 private $dateTime;
10
11 /**
12 * SomeClass constructor.
13 *
14 * @param DateTime $dateTime
15 */
16 public function __construct(DateTime $dateTime)
17 {
18 $this->dateTime = $dateTime;
19 }
20
21 /**
22 * display current date to internal format time zone
23 *
24 * @return string
25 */
26 public function getFormatDate(): string
27 {
28 return $this->dateTime->formatDate(time());
29 }
30...
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.