phplaravellaravel-4timezonelaravel-3

Laravel get TimeZone not working


Iam trying to convert UTC timezone to Singapore Time

    echo $Date->format('Y-m-d H:i:s');
    echo '<br>'; 
    echo with(new Carbon\Carbon($Date->format('Y-m-d H:i:s')))->tz('Asia/Singapore')->format('Y-m-d H:i:s');
    exit;

it works fine in Localhost but in aws server it displays utc Time for both...Both server and Localhost is set to UTC Time .. how do we fix this??


Solution

  • Try this it will work

     $timestamp ='1411205843'  //Timestamp which you need to convert 
    
     $sourceTimezone = new DateTimeZone('UTC');
    
     $destinationTimezone = new DateTimeZone('Asia/Singapore'); 
    
     $dt = new DateTime(date('m/d/Y h:i A', $timestamp), $sourceTimezone);
     $dt->setTimeZone($destinationTimezone);
    
     echo strtotime($dt->format('m/d/Y h:i A'));