Michael
Michael

Reputation: 109

PHP - unix timestamp from seconds to milliseconds

So I need to convert an unix timestamp which is in seconds to milliseconds. This line seems to be not working

$unixtime = strtotime($timestamp_conv."+3 hour") * 1000;

I basically need a 13 digit timestamp. Any ideas what I'm doing wrong?

Thanks

Upvotes: 0

Views: 2685

Answers (2)

Sirko
Sirko

Reputation: 74086

As per the comments, $timestamp_conv already is a (second-)timestamp, you want to convert to a (milliseconds-)timestamp. You, however, also try to add some offset (3 hours) to it.

With simple arithmetics this would look like this

// add the three hours: 3 hours of 60 minutes of 60 seconds each
$timestamp_conv += 3 * 60 * 60;

// convert to milliseconds base
$unixtime = $timestamp_conv * 1000;

Upvotes: 1

Keloo
Keloo

Reputation: 1408

You can use DateTime from php, it's more intuitive.

<?php
$t = new \DateTime();
$t->setTimestamp(1492498242);
$t->modify("+3 hours");
echo $t->getTimestamp()*1000;

Hope it helps!

Upvotes: 1

Related Questions