I am trying to get the local time using php. I wrote two different versions, but they both give the wrong time
date_default_timezone_set(\'UTC\');
$now = new Dat
DateTime::getTimestamp()
returns unix timestamp. That number is always UTC. What you want is format the date according to your time zone.
$dt = new DateTime("now", new DateTimeZone('America/New York'));
echo $dt->format('m/d/Y, H:i:s');
Or use a different date format, according to what you need.
Also, you can use DateTime library for all your date needs. No need to change server's default timezone every time you want to fetch the date.