How to return the timezone timestamp defined?

1

I'm trying to return the timestamp of my city.

When I use the ('Ymd H: i: s') statement it returns the correct time for my region but I need to return timestamp timestamp of my region's time.

function agora (){
    date_default_timezone_set("America/Campo_Grande");
    $dftz011 = date_default_timezone_get();
    $dtms011 = new DateTime();
    return $dtms011->format('U'); 
}

I'm using this tool to convert the returned timestamp and when I do the conversion I always return the server time and not the timezone of my region.

How to return the timestamp of my region?

    
asked by anonymous 08.10.2015 / 05:13

1 answer

5

To get the converted timestamp with timezone, add timestamp to the offset (greenwitch in seconds). Use the methods getTimestamp () and getOffset () of the DateTime class.

<?php
$data = new DateTime('now', new DateTimeZone("America/Sao_Paulo"));
echo 'TimeStamp: '. ($data->getTimestamp() + $data->getOffset());

Output: 1444269422, matches: Thu, 08 Oct 2015 01:57:02 GMT

Example - 3v4l

Example with funny message - ideone

References

epochconverter

How to get Unix timestamp in php based on timezone

Adjusting Timestamps for Time Zones

    
08.10.2015 / 06:58