Copyright © tutorialspoint.com
| string date ( string $format [, int $timestamp] ); |
Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time().
| Parameter | Description |
|---|---|
| format | Required. Specifies how to return the result:
|
| timestamp | Optional. This is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time(). |
Returns a formatted date string. If a non-numeric value is used for timestamp, FALSE is returned and an E_WARNING level error is emitted.
Following is the usage of this function:
<?php
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('UTC');
// Prints something like: Monday
echo date("l");
echo "\n";
// Prints something like: Monday 15th of August 2005 03:12:46 PM
echo date('l dS \of F Y h:i:s A');
echo "\n";
// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l",
mktime(0, 0, 0, 7, 1, 2000));
echo "\n";
/* use the constants in the format parameter */
// prints something like: Mon, 15 Aug 2005 15:12:46 UTC
echo date(DATE_RFC822);
echo "\n";
// prints something like: 2000-07-01T00:00:00+00:00
echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
?>
|
This will produce following result:
Sunday Sunday 19th of August 2007 08:17:47 AM July 1, 2000 is on a Saturday Sun, 19 Aug 07 08:17:47 +0000 2000-07-01T00:00:00+00:00 |
Copyright © tutorialspoint.com