Pergunta

I tried to get todays time at 00:01:00 (h:i:s)

my code:

<?php 
$delay_hour=10;
$delay_minute=11;

echo $t2=mktime($delay_hour, $delay_minute, 00, date('n',time()), date('j',time()), date('Y',time()));
echo '<br/>';
echo date("d-m-Y h:i:s",$t2);
echo '<br/>';
$delay_hour=0;
$delay_minute=1;

echo $t2=mktime($delay_hour, $delay_minute, 00, date('n',time()), date('j',time()), date('Y',time()));
echo '<br/>';
echo date("d-m-Y h:i:s",$t2);
echo '<br/>';
?>

so how to get todays time at 00:01:00?

Foi útil?

Solução

Your code can be simplified to just:

$result = mktime(0,1,0);//hour, minute, second

Because mktime() without date part passed to it will set date to today's date.

Note also, that mktime() results in timestamp - i.e. it's not formatted date, it's integer value (equal to number of seconds passed since Unix Epoch beginning)

Outras dicas

var_dump(strtotime(date('Y-m-d').' 00:01:00'));

or

$date = new DateTime('today 00:01:00');
var_dump($date->format('Y-m-d H:i:s')); // formatted
var_dump($date->format('U')); // timestamp

or

var_dump(mktime(0, 1));

If you need formatted representation, it is prefered to use second approach, with DateTime. If you need timestamp, use third, with mktime

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top