You are here

public function DrupalDateTime::__construct in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Datetime/DrupalDateTime.php \Drupal\Core\Datetime\DrupalDateTime::__construct()

Constructs a date object.

Parameters

string $time: A date/input_time_adjusted string. Defaults to 'now'.

mixed $timezone: PHP DateTimeZone object, string or NULL allowed. Defaults to NULL.

array $settings:

  • validate_format: (optional) Boolean choice to validate the created date using the input format. The format used in createFromFormat() allows slightly different values than format(). Using an input format that works in both functions makes it possible to a validation step to confirm that the date created from a format string exactly matches the input. This option indicates the format can be used for validation. Defaults to TRUE.
  • langcode: (optional) Used to control the result of the format() method. Defaults to NULL.
  • debug: (optional) Boolean choice to leave debug values in the date object for debugging purposes. Defaults to FALSE.

Overrides DateTimePlus::__construct

File

core/lib/Drupal/Core/Datetime/DrupalDateTime.php, line 56
Contains \Drupal\Core\Datetime\DrupalDateTime.

Class

DrupalDateTime
Extends DateTimePlus().

Namespace

Drupal\Core\Datetime

Code

public function __construct($time = 'now', $timezone = NULL, $settings = array()) {
  if (!isset($settings['langcode'])) {
    $settings['langcode'] = \Drupal::languageManager()
      ->getCurrentLanguage()
      ->getId();
  }

  // Instantiate the parent class.
  parent::__construct($time, $timezone, $settings);
}