DrupalDatetime example

$this->installConfig(['system']);

    // Setup the background time zones.     $this->timezones['php initial'] = date_default_timezone_get();
    $user = $this->createUser();
    $user->set('timezone', $this->timezones['user'])->save();
    // This also sets PHP's assumed time.     \Drupal::currentUser()->setAccount($user);

    // Set a reference date to use in tests.     $this->date = new DrupalDatetime('2000-01-01 12:00', NULL);

    // Create arrays listing the dates and times of $this->date formatted     // according to the various timezones of $this->timezones.     $this->dateFormat = DateFormat::load('html_date')->getPattern();
    $this->timeFormat = DateFormat::load('html_time')->getPattern();
    $date = clone $this->date;
    foreach ($this->timezones as $label => $timezone) {
      $date->setTimezone(new \DateTimeZone($timezone));
      $this->formattedDates['date'][$label] = $date->format($this->dateFormat);
      $this->formattedDates['time'][$label] = $date->format($this->timeFormat);
      $this->formattedDates['day'][$label] = $date->format('j');
      
Home | Imprint | This part of the site doesn't use cookies.