nshah
nshah

Reputation: 597

Current Time in DateTime PHP

Is this the correct way to get the current time in PHP using DateTime?

$currenttime = new DateTime();
$currenttime2 = $currenttime->format('H:i:s');

Upvotes: 0

Views: 148

Answers (2)

kwolfe
kwolfe

Reputation: 1683

This will set the time based on your date time settings in php.ini. Do a var_dump of $currenttime after creation to see what I mean. You may also use microtime(true); to obtain a unix timestamp, which can be converted using other functions.

Upvotes: 0

James R
James R

Reputation: 276

I believe you can do it like this

$date = date('Y-m-d H:i:s');

Upvotes: 1

Related Questions