Skip to main content
add change record for D8.5
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

Use the global constant DATETIME_DATETIME_STORAGE_FORMAT to format the date:

// If the time is in a different timezone then adjust it to UTC before you save it
$date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));

$paragraph = Paragraph::create([
  ...
  'field_date' => [
    'value' => $date->format(DATETIME_DATETIME_STORAGE_FORMAT),
  ],
]);

Edit

For Drupal >= 8.5: Global constants in datetime.module are deprecated and DateTimeItemInterface has been introduced.

Use the global constant DATETIME_DATETIME_STORAGE_FORMAT to format the date:

// If the time is in a different timezone then adjust it to UTC before you save it
$date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));

$paragraph = Paragraph::create([
  ...
  'field_date' => [
    'value' => $date->format(DATETIME_DATETIME_STORAGE_FORMAT),
  ],
]);

Use the global constant DATETIME_DATETIME_STORAGE_FORMAT to format the date:

// If the time is in a different timezone then adjust it to UTC before you save it
$date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));

$paragraph = Paragraph::create([
  ...
  'field_date' => [
    'value' => $date->format(DATETIME_DATETIME_STORAGE_FORMAT),
  ],
]);

Edit

For Drupal >= 8.5: Global constants in datetime.module are deprecated and DateTimeItemInterface has been introduced.

added 8 characters in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

Use the global constant DATETIME_DATETIME_STORAGE_FORMAT to format the date:

// If the time is in a different timezone then adjust it to UTC before you save it
$date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));

$paragraph = Paragraph::create([
  ...
  'field_date' => [
    'value' => $date->format(DATETIME_DATETIME_STORAGE_FORMAT),
  ],
]);

If the time is in a different timezone then adjust it to UTC before you save it:

$date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));

Use the global constant DATETIME_DATETIME_STORAGE_FORMAT to format the date:

$paragraph = Paragraph::create([
  ...
  'field_date' => [
    'value' => $date->format(DATETIME_DATETIME_STORAGE_FORMAT),
  ],
]);

If the time is in a different timezone then adjust it to UTC before you save it:

$date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));

Use the global constant DATETIME_DATETIME_STORAGE_FORMAT to format the date:

// If the time is in a different timezone then adjust it to UTC before you save it
$date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));

$paragraph = Paragraph::create([
  ...
  'field_date' => [
    'value' => $date->format(DATETIME_DATETIME_STORAGE_FORMAT),
  ],
]);
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

Use the global constant DATETIME_DATETIME_STORAGE_FORMAT to format the date:

$paragraph = Paragraph::create([
  ...
  'field_date' => [
    'value' => $date->format(DATETIME_DATETIME_STORAGE_FORMAT),
  ],
]);

If the time is in a different timezone then adjust it to UTC before you save it:

$date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));