Awesome q2a theme

How to spend the time transformation to create a timer in PHP?

0 like 0 dislike
32 views
Problem: when an event occurs, we need to record the current time + 3 hours in a Mysqli database (in what format it is better to do that then not to bother with conversion?).
And next, when entering the page to show the timer with hours, minutes and seconds that remain until the posted time. As PHP is easier to obtain the difference between the current time and time in the future, and then arrange to count it in the format remained much the hours, minutes and seconds.

I.e. conditionally at midnight, an event occurred at three o'clock - the end of the fairy tale of Cinderella. now two hours eight minutes. have been written to the database time (three hours) minus the current output in the format suitable for the timer
by | 32 views

1 Answer

0 like 0 dislike
$d1 = new \\DateTime("2018-04-26 03:00:00"); // the time of the event $d2 = new \\DateTime(); // Current time $diff = $d1->diff($d2); // Difference print_r($diff) ; // DateInterval Object ( [y] => 0 [m] => 0 [d] => 0 [h] => 1 [i] => 39 [s] => 21 [f] => -0.909875 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 1 [days] => 0 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 )

\rphp.net/manual/ru/class.dateinterval.php

In the database store in a DateTime or UnixTimestamp
by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
110,608 questions
257,187 answers
0 comments
40,796 users