Format date and time in a readable form in PHP

Description

The following code shows how to format date and time in a readable form.

Example


<!DOCTYPE html>/*w w  w  . j  av  a2s .  c  o m*/
<html>
  <body>
    <h1>
    <?php 
    
    // Get the current time in a readable format
    $currentTime = date( "g:i:s a" );
    
    // Get the current date in a readable format
    $currentDate = date( "M j, Y" );
    
    // Display greeting, time and date to the visitor
    
    echo "Hello, world! The current time is $currentTime on $currentDate"; 
    ?>
    </h1>
  </body>
</html>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone