Display date and time in PHP

5

I'm trying to display the exact time with PHP in the following format.

  

Date: YYYY-MM-DD

     

Time: 00: 00: 00: 000

  <?php 
       setlocale( LC_ALL, 'pt_BR', 'pt_BR.iso-8859-1', 'pt_BR.utf-8', 'portuguese' ); 
       date_default_timezone_set( 'America/Sao_Paulo' );
       echo strftime( '%Y-%m-%e %T', strtotime('today')); 
?>

With the current code it according to my search would display this for example, 2015-01-26 00:00:00

I'm using windows7 x64 and PHP Version 5.5.8 and the page does not display anything or errors.

    
asked by anonymous 26.01.2015 / 18:35

4 answers

8

The problem is the strftime function, which does not do the timestamp conversion correctly on windows, some arguments such as alert documentation are not supported:

%e, %T, %R, %D

For your code to work, change %e and %T to,

%d for day with two digits 01-31.

%H to display the time in format 00-23

%M for minutes in format 00-59

%S For second in format 00-59

The code should look like this:

echo strftime( '%Y-%m-%d %H:%M:%S', strtotime('today') );

List with supported arguments in windows - msdn

    
26.01.2015 / 18:58
2

Try it out:

<?php echo date('Y-m-d H:i:s') ?>
    
26.01.2015 / 18:57
1

Your problem is in strtotime where you put today , translating, hoje . Try to put now ( agora ).

echo strftime( '%Y-%m-%e %T', strtotime('now'));
    
26.01.2015 / 19:03
1

To display: Date: YYYY-MM-DD and with the current time:

<?php

    $date = date('Y-m-d H:i:s:u');
    echo $date;


?>
    
26.01.2015 / 19:12