Jump to content

[SOLVED] Help generate time code


rondog

Recommended Posts

Can anyone help me think of a way to generate a time code string? I need the format like this:

"00:00:00.00"
"00:00:10.00"
"00:00:20.00"
"00:00:30.00"
-------
"00:50:10.00"
"00:50:20.00"
"00:50:30.00"

etc...

 

I need to basically make a loop that will add $seconds (I can make this whatever..in my example is 10 seconds) and continue for X amount of loops. I realized this will be a very long loop. I am just using it to copy/paste this information so I dont have to type it all.

 

 

Link to comment
https://forums.phpfreaks.com/topic/161382-solved-help-generate-time-code/
Share on other sites

<?php
// generate a list of date/time values

function add_interval($datetime,$interval){
return date('Y-m-d H:i:s',strtotime("$datetime + $interval"));
} // end of add_interval function

$interval = '30 seconds'; // format that strtotime() can use, the resolution of the display grid (15 min, 30 min, 1hr, 2hr...) - should be evenly divisible into the next higher unit
$display_start = '2009-05-14 00:00:00'; // the datetime to start the display
$display_stop = '2009-05-14 00:50:30'; // the datetime to stop the display

for($i = $display_start; $i <= $display_stop; $i = add_interval($i,$interval)){
// $i is a datetime yyyy-mm-dd hh:mm:ss
//echo "$i.00<br />";
echo substr($i, - . ".00<br />"; // get the hh:mm:ss.00 portion of the value
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.