0

How can i run this code on PHP 5.1.6

$tz = new DateTimeZone($obj['timezone']);

without upgrading my PHP version?

or is there any alternative?

I'am getting this error

PHP Fatal error: Class 'DateTimeZone' not found

Thank you

uno
  • 867
  • 2
  • 14
  • 29
  • Its not supported in version 5.1.6 but supported in (PHP 5 >= 5.2.0, PHP 7) – Rakesh Sojitra Oct 24 '16 at 05:28
  • Did you check http://stackoverflow.com/questions/28568992/php-5-3-fatal-error-class-datetimezone-not-found – jitendrapurohit Oct 24 '16 at 05:28
  • Only: http://php.net/manual/ru/function.date-default-timezone-set.php – Deep Oct 24 '16 at 05:30
  • 1
    WHY are you running 5.1? Can I please know the URL where you're hosting this as I can imagine that there's a good amount of nice and abusive security flaws in a product that **stopped security updates more than 10 years ago** (*24 August 2006*)? [On the bright side there's "only" 118 vunerabilities and 12 exploits](http://www.cvedetails.com/version/36749/PHP-PHP-5.1.6.html) – h2ooooooo Oct 24 '16 at 07:17

2 Answers2

0

PHP 5.1.x has only experimental support for DateTime

http://php.net/manual/en/datetime.installation.php

Note: Experimental DateTime support in PHP 5.1.x

Although the DateTime class (and related functions) are enabled by default since PHP 5.2.0, it is possible to add experimental support into PHP 5.1.x by using the following flag before configure/compile: CFLAGS=-DEXPERIMENTAL_DATE_SUPPORT=1

M. Furqan
  • 31
  • 3
0

date_default_timezone_set('America/Los_Angeles'); //set your timezone

$tz = date_default_timezone_get(); //display timezone

$date = date('Y:m:d'); //display date