How to choose date in timestamp

Asked

Viewed 86 times

0

I have the following line of code:

round(microtime(true) * 1000)

in order to catch the timestamp in milliseconds of the current time. I need to pick a future date, example, 10 or 5 minutes ahead. How can I do this?

  • This question may also help you: http://stackoverflow.com/questions/8841135/how-to-change-a-unix-timestamp-in-the-future-to-seconds-remaining

2 answers

2


One option is to use the function DateTime::add:

$dataQualquer = new DateTime();
$dataQualquer->add(new DateInterval('PT10M')); // 10 minutos no futuro
echo 'Timestamp:'.$dataQualquer->getTimestamp();

2

You can use the time PHP, which returns the team in seconds.

<?php
// time atual em segundos
$now = time();
// adicionando 5 minutos
$futuro5min = $now + (5*60);
// adicionando 10 minutos
$futuro = $now + (10*60);
?>

Remember that the timestamp is in seconds. To get in milliseconds, just multiply the final result by 1000.

http://php.net/time

Browser other questions tagged

You are not signed in. Login or sign up in order to post.