DrupalDateTime class not work I try to use &quot;DrupalDateTime&quot; class in my theme to show native date and time in custom format based on special TimeZone in my nodes.
According to this article: New Datetime API

Drupal core and contributed modules should use the DrupalDateTime
class in preference to the PHP DateTime class or to functions like
date(), gmdate(), strtotime(), etc.
the class incorporates the IntlDateFormatter into its format() method,
if the IntlDateFormatter is available, and otherwise falls back to
wrapping formatted output with Drupal's translation system. The
IntlDateFormatter requires additional information, which can be passed
in a settings array.

And then I add below code to MyThmeName.theme:
Note: Be sure to add use Drupal\Core\Datetime\DrupalDateTime; at the top of any files that use this class.
function MyThemeName_preprocess_node(&amp;$variables){
  $node_date = $variables['node']-&gt;getCreatedTime();
  $date = new DrupalDateTime($node_date, 'UTC');
  $date-&gt;setTimezone(new \DateTimeZone('Asia/Tehran'));
  $variables['date'] = $date-&gt;format('Y/m/d'); }

I'm sure PHP intl extension was exist! I cleared comment before this line in php.ini file:
;extension=php_intl.dll

I get below error:
Exception: DateTime object not set. in Drupal\Component\Datetime\DateTimePlus-&gt;__call() (line 308 of core\lib\Drupal\Component\Datetime\DateTimePlus.php).


Update:
I'm following kiamlaluno solution carefully
but the result not changed and date is shown in the English language yet and howsoever I try I can't get an appropriate result to show date and time in my native calendar, where is the problem, is there other parameters that should be set.
if (isset($variables['node'])) {
  $date = DrupalDateTime::createFromTimestamp($variables['node']-&gt;getCreatedTime(), new \DateTimeZone('Asia/Tehran'), ['langcode' =&gt; 'fa']);
  $variables['date'] = $date-&gt;format('Y/m/d');
}

Thanks for any help.
The code you are showing is wrong because DrupalDateTime::__construct() is expecting a string, while you are passing an integer, which is what Node::getCreatedTime() returns.

Instead of DrupalDateTime::__construct(), you should use DrupalDateTime::createFromTimestamp().

$date = DrupalDateTime::createFromTimestamp($variables['node']-&gt;getCreatedTime(), 'UTC');


Since the static method also accept a \DateTimeZone object as second parameter, your code could be similar to the following one.

if (isset($variables['node'])) {
  $date = DrupalDateTime::createFromTimestamp($variables['node']-&gt;getCreatedTime(), new \DateTimeZone('Asia/Tehran'));
  $variables['date'] = $date-&gt;format('Y/m/d');
}


Since you seem interested to get strings in a specific language, you should also set the language code.

if (isset($variables['node'])) {
  $date = DrupalDateTime::createFromTimestamp($variables['node']-&gt;getCreatedTime(), new \DateTimeZone('Asia/Tehran'), ['langcode' =&gt; 'the language code for the language you need']);
  $variables['date'] = $date-&gt;format('Y/m/d');
}