Created
July 25, 2020 06:41
-
-
Save cp6/4b12df0fff597726e133676f680379ef to your computer and use it in GitHub Desktop.
PHP generate random time from timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function randomTimeFormatted(string $max_time): string | |
{ | |
$t = explode(':', $max_time); | |
return sprintf("%02d:%02d:%02d", rand(0, $t[0]), rand(0, $t[1]), rand(0, $t[2])); | |
} | |
echo randomTimeFormatted('02:38:55'); | |
//02:38:55 will make random string from 0->2 hours, 0->38 mins, 0->55 seconds | |
//Could return 01:24:33 etc | |
//Wont return anything greater than 02:38:55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment