-3

i want ask php,

Date now is : 10:10:10 18/08/2020

Router Uptime is : 1w1d11h1m1s

when is date of turning on the Router? example 10:10:10 11/08/2020

Need function php with format date H:i:s d/m/Y

New EDIT add example function:

$uptime = "1w1d11h1m1s";

function turn_on($uptime)
{
$w = str_replace('w', ' weekdays', $uptime);
$d = str_replace('d', ' days', $uptime);
$h = str_replace('h', ' hours', $uptime);
$i = str_replace('m', ' minutes', $uptime);
$s = str_replace('s', ' seconds', $uptime);

echo 'date is' . ('H:i:s d/m/Y' ,strtotime(' - '. $w $d $h $i $s ));
}

Thanks for everybody who can help me

james bond
  • 107
  • 1
  • 9
  • Does this answer your question? [Adding days to $Date in PHP](https://stackoverflow.com/questions/3727615/adding-days-to-date-in-php) – Alok Mali Aug 18 '20 at 12:58
  • 1
    not same sir, my input format XwXdXhXmXs to output H:i:s d/m/Y – james bond Aug 18 '20 at 13:08
  • There isn't a builin function to parse your router's interval format, you'll need to roll your own. For that, you'll possibly need to gather some information about the format—at least something more than one example. – Álvaro González Aug 18 '20 at 13:37
  • EDIT add example function, router just example device sir. hiks now vote -3 – james bond Aug 18 '20 at 14:01
  • Your function doesn't look bad but we don't really know much about the format. Are the tokens shown mandatory? Can there be additional ones such as months or years? – Álvaro González Aug 18 '20 at 16:38

1 Answers1

1

unless you can get $uptime reformatted, you would need to split it first then convert it to a timestamp and output it as you prefer:-

public function turn_on($uptime)
{    
    $items = preg_split('/[^0-9]/i', $uptime);
 
    $timeStamp =  strtotime("- $items[0] week 
                             $items[1] days 
                             $items[2] hours 
                             $items[3] minutes 
                             $items[4] seconds");

    return date('H:i:s d/m/Y', $timeStamp);
}
Chris
  • 987
  • 2
  • 12
  • 25