Joomla! Programmierung/Framework/JHtml/date

Aus Joomla! Dokumentation
Wechseln zu: Navigation, Suche

Formatiert ein Datum in Abhängigkeit zur hiesigen Zeit und fügt einen Offset hinzu.

Inhaltsverzeichnis

[Bearbeiten] Syntax

static date( $date, [$format], [$offset] )
  • @return string das formatierte Datum
  • @since Joomla 1.5
Parameter Datentyp Beschreibung Standardwert
$date string Zeit und Datum. Siehe auch JFactory::getDate und JDate.
$format string Optionales Format der Ausgabe für strftime null
$offset int Ein optionaler Offset für die Zeit. Falls nicht gegeben, wird der Offset aus der globalen KonfigurationToDo Verlinken benutzt. null

[Bearbeiten] Beispiele

[Bearbeiten] Datum ausgeben

$datum = '2009-06-25 19:32:45';
 
echo JHtml::_('date', $datum);

Ausgabe bei deutschem Sprachfile:

Donnerstag, 25. Juni 2009

[Bearbeiten] Siehe auch

[Bearbeiten] Quellcode

JHtml::date in Joomla! 2.5.4

Folder blue.png libraries

  • Folder red.png joomla
    • Folder green.png html
      • File php.png html.php
  1. public static function date($input = 'now', $format = null, $tz = true, $gregorian = false)
  2. {
  3. // Get some system objects.
  4. $config = JFactory::getConfig();
  5. $user = JFactory::getUser();
  6.  
  7. // UTC date converted to user time zone.
  8. if ($tz === true)
  9. {
  10. // Get a date object based on UTC.
  11. $date = JFactory::getDate($input, 'UTC');
  12.  
  13. // Set the correct time zone based on the user configuration.
  14. $date->setTimeZone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
  15. }
  16. // UTC date converted to server time zone.
  17. elseif ($tz === false)
  18. {
  19. // Get a date object based on UTC.
  20. $date = JFactory::getDate($input, 'UTC');
  21.  
  22. // Set the correct time zone based on the server configuration.
  23. $date->setTimeZone(new DateTimeZone($config->get('offset')));
  24. }
  25. // No date conversion.
  26. elseif ($tz === null)
  27. {
  28. $date = JFactory::getDate($input);
  29. }
  30. // UTC date converted to given time zone.
  31. else
  32. {
  33. // Get a date object based on UTC.
  34. $date = JFactory::getDate($input, 'UTC');
  35.  
  36. // Set the correct time zone based on the server configuration.
  37. $date->setTimeZone(new DateTimeZone($tz));
  38. }
  39.  
  40. // If no format is given use the default locale based format.
  41. if (!$format)
  42. {
  43. $format = JText::_('DATE_FORMAT_LC1');
  44. }
  45. // format is an existing language key
  46. elseif (JFactory::getLanguage()->hasKey($format))
  47. {
  48. $format = JText::_($format);
  49. }
  50.  
  51. if ($gregorian)
  52. {
  53. return $date->format($format, true);
  54. }
  55. else
  56. {
  57. return $date->calendar($format, true);
  58. }
  59. }
Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Sonstiges
Team Navigation
Werkzeuge