Working with DateTime in Doctrine 2 and Zend Framework 2

The problem

Storing datetimes can be a issue if servers and users of your application are distributed around the World and use different time zones. Each user want to work on datetimes in his specific time zone, servers automatically stores values in their time zone, etc. Storing data without operating right conversion will cause strange behaviours.

The solution

The solution is very simple: store all datetimes in UTC time zone and show to each user in his proper time zone. This is, gnerally, a well documented technique, but the following code will explain how to realize this operation in Doctrine 2 and Zend Framework 2 environment. To do this, we will assume you just have a working ZF2 project with a configured DoctrineORMModule (refer to official documentation to reach this achievement).

Continua a leggere