"Class not found" error when attempting to access inbuilt DateTime class I am attempting to convert a working Drupal 6 module to Drupal 8 in preparation for the up coming release, and as an exercise in learning the new system.

In my existing module, I do some calculations on whether or not it is currently the weekend or a weekday and output some HTML in a block based on that.

In my code I have a is_weekend() function which returns TRUE if it is currently the weekend, and FALSE if it is a weekday.

My code for that function starts like this.

function is_weekend() {
  $ESTTZ = new DateTimeZone('America/New_York');
  $dt = new DateTime();
  $dt-&gt;setTimezone($ESTTZ);
  $day = $dt-&gt;format("w");
  $hour = $dt-&gt;format("H");
  $minute = $dt-&gt;format("i");
  $weekend = FALSE;

  if ($day == 6) {
    // ...
  }

  return $weekend;
}


It works fine; however, when I try to put this function into my new block class I get the following error:


  Fatal error: Class 'Drupal\livequotes\Plugin\Block\DateTimeZone' not found in C:\Work\ex-global-8


How can I call this PHP class from within my own block class?
You're just running into namespace problems. DateTimeZone is in the root namespace, so refer to it as:

\DateTimeZone


Same for

\DateTime