problems saving time

1

Greetings friends I have a problem when the time is saved it turns out that if it is 12:45 p.m. it saves me the time 12:15:47 PM the format I use is the following:

 <?php
 date_default_timezone_set('America/Caracas');
 ?>
 <input type='hidden' name='hora' value='<?php echo date('h:i:sA'); ?>' />

    
asked by yoclens 13.07.2017 в 18:54
source

2 answers

1

At the moment of answering, in Caracas they should be the 02:38PM

Look at the code examples. If you do not want the seconds, you just have to omit the s .

If it does not work for you, the problem is elsewhere, not in the code.

Código: Ver Demo

<?php

date_default_timezone_set('America/Caracas'); 
echo date('H:i:sA');
echo "\n";
echo date('h:i:sA');
echo "\n";
echo date('H:iA');
echo "\n";
echo date('h:iA');

?>

Resultado

14:38:06PM
02:38:06PM
14:38PM
02:38PM

EDIT

You can also use PHP's DateTime class, which is more flexible and powerful than the date function.

You create a $date object by new and apply the zone to it. Then you make echo of the object with the format you want.

Example:

Code:

$date = new DateTime("now", new DateTimeZone('America/Caracas'));
echo $date->format('H:i:sA');

Result:

14:54:35PM
    
answered by 13.07.2017 в 20:40
0

Test Adding or subtracting missing minutes

<?php
$time = time();
?>
<input type='hidden' name='hora' value='<?php  echo date("d-m-Y (H:i:s)", $time +1800); ?>' />
    
answered by 13.07.2017 в 19:16