As we know coding Standard for Magento 2.x changed as compared to Magento 1.x
so in order to get the Date and Time in Magento 2.x
we need to inject in our class constructor an instance of
\Magento\Framework\Stdlib\DateTime\DateTime and use that one.
Something like this:
public function __construct(
$this->date = $date;
and the we can use in our Function
$date = $this->date->gmtDate();
$date = $this->date->date();
$date = $this->date->date(‘Y-m-d H:i:s’);
hope this will help you.