user1514879
user1514879

Reputation:

php get date from epoch ms

I have a field in ms from epoch, like 1350393140000. I need to, in PhP, get this field as a datetime, change the time portion of it to 7AM (UTC time) and convert it back to ms from epoch. How can I do this?

Upvotes: 0

Views: 384

Answers (2)

deceze
deceze

Reputation: 522461

date_default_timezone_set('UTC');
$ts = 1350393140000 / 1000;
$ts = mktime(7, date('i', $ts), date('s', $ts), date('n', $ts), date('j', $ts), date('Y', $ts));
$ts = $ts * 1000;

Upvotes: 0

Evert
Evert

Reputation: 99697

$input = 1350393140000;

$dt = new DateTime('@' . floor($input / 1000));
$dt->setTimeZone(new DateTimeZone('UTC'));
$dt->modify('07:00');

$output = $dt->format('U') * 1000;

Upvotes: 2

Related Questions