An offset applied in this way only affects the
resultant date and time when using the toFormat() method.
One useful thing to be aware of, when working with dates and time, is the
application requestTime. The requestTime is a date and time that is recorded by
the application when a request is made.
This example demonstrates how we can access the requestTime and output it using
the DATE_FORMAT_LC2 format:
$rDate = new JDate($mainframe->get('requestTime'));
echo $rDate->toFormat(JText::_('DATE_FORMAT_LC2'));
The final aspect that we will touch on is the use of JHTML, discussed in Chapter 8, to
output a date. If all we are trying to do is parse a date so that we can apply a format
and an offset, we can use the basic JHTML date type.
This example outputs the requestTime time using the DATE_FORMAT_LC2 format:
// get the date and time of the request
$date = $mainframe->get('requestTime');
// output the date and time
echo JHTML::_('date', $date, JText::_('DATE_FORMAT_LC2'));
The nice thing about using this is that it automatically applies the site time zone
offset to the date if we do not specify the offset ourselves.
Pages:
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477