JFactory/getDate
Returns a reference to the global date object, only creating it if it doesn't already exist. The object returned will be of type JDate.
Contents |
Syntax
object JDate getDate( $time, $tzOffset )
where:
| Argument | Data type | Description | Default |
|---|---|---|---|
| $time | string or unsigned integer | The date and time to use. To use the current (server) date and time use 'now'. The format to be used will depend on the current language and on whether the default Gregorian calendar has been overridden (which can only be done per language). See JLanguage for more information. If an integer is specified then the date is interpreted as a Unix timestamp. | 'now' |
| $tzOffset | signed integer | The timezone offset to apply to the data and time in $time. This is subtracted from the $time when calculating the date/time so that the date saved in the date object is in UT (often referred to as GMT). See the examples below.
|
0 |
Example 1
In this example, the current date and time is retrieved and output in the current default locale format.
$date =& JFactory::getDate(); echo 'Current date and time is: ' . $date->toFormat() . "\n";
If the current language is English then this will output something like
Current date and time is: 2008-11-22 18:14:08
Example 2
In this example, a date is specified (using the English Gregorian calendar) and output in RFC2822 format suitable for use in most internet protocols. Note that for this to work the date must be specified in the current locale format or the date parser may not recognise it. A timezone offset of +1 is also specified, perhaps indicating that the date is in Central European Time (CET) which is one hour ahead of UT. Notice how the time output has been adjusted to UT.
$date =& JFactory::getDate( '16 April 2008 14:30:00', 1 ); echo 'Date and time is: ' . $date->toRFC822() . "\n";
Which will output this
Date and time is: Wed, 16 Apr 2008 13:30:00 +0000
Example 3
In this example, the date is specified as a Unix timestamp and output in ISO 8601 format.
$date =& JFactory::getDate( 1332362632 ); echo 'Date and time is: ' . $date->toISO8601() . "\n";
Which will output this
Date and time is: 2012-03-21T20:43:52Z