Get current time with php

1

This code returns the current time, but I need it a minute ago.

  <input type="text" value="<?php echo date("h:i:s A");?>">

Can you do that if the current time is 2pm; the input show me the 13:59?

    
asked by Johan Solano Contreras 30.08.2018 в 08:41
source

2 answers

1

The second (optional) argument of the date() function is a timestamp . So you can put the format as the first argument and as a second argument strtotime("-1 minute") :

  <input type="text" value="<?php echo date("h:i:s A", strtotime("- 1 minute"));?>">
    
answered by 30.08.2018 / 08:55
source
1

You can use strtotime for it

$nuevafecha = strtotime ( '-1 minute' , strtotime ( date("h:i:s A")) ) ;

<input type="text" value="<?php echo $nuevafecha ;?>">

Calculated in the input directly

<input type="text" value="<?php echo strtotime ( '-1 minute' , strtotime ( date("h:i:s A")) );?>">
    
answered by 30.08.2018 в 08:49