9

I have started my ZF2 application from Skeleton-Application. I want instance of Date class in one of my controller. I tried to search Date.php class under...

library\Zend\

but could not found. Does ZF2 has not Date.php at all or I need to palce it from somewhere else?

Hanmant
  • 4,628
  • 2
  • 18
  • 21

2 Answers2

18

Zend_Date has been removed in favor of PHP 5.3 DateTime API http://es.php.net/manual/en/book.datetime.php

Maks3w
  • 6,014
  • 6
  • 37
  • 42
  • Thank you Maks3w. But how can i then use Date utilities in controllers? I mean which plugin or class should i intantiate for Date utilities? – Hanmant Sep 13 '12 at 07:58
  • I don't understand, Which Date utilities? almost all features of Zend_Date are provided by PHP 5.3 – Maks3w Sep 13 '12 at 08:02
  • Maks3w, let say for example, in ZF 1.x it has wrapper class 'Zend_Date' (derived from Zend_Date_DateObject). This class has friedly methods to operate on Dates like... Zend_Date::getUnixTimestamp Zend_Date::mktime Zend_Date::isYearLeapYear Zend_Date::dayOfWeek etc... My question is 'Does ZF2 has a wrapper class as 'Zend_Date' in ZF1.x? If not then do i need to use plain PHP Date statements throughout the code or need to write my own wrapper?' – Hanmant Sep 13 '12 at 10:22
  • No, the decision of ZF2 board was remove Zend_Date and don't supply any wrapper or other kind of friendly use. Personally I prefer to have a wrapper because, IMHO, PHP 5.3 DateTime API is very ugly and cryptographic – Maks3w Sep 13 '12 at 10:50
  • 3
    Thank you Maks3W for valuable information. As of now i will proceed with writing my own Plugin to wrap Date utilities. – Hanmant Sep 13 '12 at 11:02
  • 1
    Hanmant Please, when you finish send a Pull Request to the ZF2 GitHub repository to propose include your code with the framework – Maks3w Sep 13 '12 at 11:04
  • Hi again Maks3w, I just completed with my DateTime plugin for ZF2 [named as DateManager]. Actually I was needed it because my application is mostly oriented around date, time and timezone utilities. Written plugin is not a state-of-art one but it is good :) – Hanmant Oct 17 '12 at 10:06
1

Don't forget to call DateTime() in Zend Framework 2 like base class.
Like:

$date = new \DateTime($str);

where $str is a string from which you create date object.

laalto
  • 150,114
  • 66
  • 286
  • 303