How can I get the current date and time in PHP?

Member

lily.simonis

by lily.simonis , in category: PHP , a month ago

How can I get the current date and time in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by laury_ullrich , a month ago

@lily.simonis There are multiple ways to do that. You can use built-in php function time(), example:


1
2
3
4
5
6
<?php

$date = date('H:i:s', time());

// 19:05:59
echo $date;


You can use DateTime object as well to get the current date and time, example:


1
2
3
4
5
6
<?php

$dateTime = new DateTime('now');

// 19:05:59
echo $dateTime->format('H:i:s');