Time and date manipulation would appear in most PHP applications. PHP provides a nice method to create timestamp using strtotime. The PHP documentation gives the types of arguments we could pass in strtotime to get the timestamp.
For creating the current timestamp we could use something like below
strtotime(date('Y-m-d H:i:s'));
Please note that date function in php works based on the timezone settings for the application set in the application. We could also set the timezone using the method date-default-timezone-set.
The time conversion and display would be tricky sometimes. It would be better that we store the date time in GMT in database so that even when we change the timezone, it would work fine and display the correct time as conversion from GMT to the existing timezone is easier.
When creating a timestamp value from a GMT date time value using strtotime, we should append the date time value with "+00:00". This would create the correct timestamp related to the GMT.
For creating the current timestamp we could use something like below
strtotime(date('Y-m-d H:i:s'));
Please note that date function in php works based on the timezone settings for the application set in the application. We could also set the timezone using the method date-default-timezone-set.
The time conversion and display would be tricky sometimes. It would be better that we store the date time in GMT in database so that even when we change the timezone, it would work fine and display the correct time as conversion from GMT to the existing timezone is easier.
When creating a timestamp value from a GMT date time value using strtotime, we should append the date time value with "+00:00". This would create the correct timestamp related to the GMT.
No comments:
Post a Comment