Q: How can I obtain the current system time in magento?
// This time will not match your server time $ now = Time (); echo date ('m/D/y h: I: s', time ());
If you try to obtain the current time of the system in magento, you may be confused about the result. :-) Why is the current time incorrect?
At this time, you may think that the time zone settings in PHP. ini may be incorrect. However, after you check it out, you will find that the reason is not here.
In fact, this is because the mage_core_model_app class in magento resets the time zone.
File:- /app/code/core/Mage/Core/Model/App.php Line:-255
| |
date_default_timezone_set(Mage_Core_Model_Locale::DEFAULT_TIMEZONE); |
After finding the cause, the problem will be easy. Now we can get the current time using the following method:
| |
$now = Mage::getModel(
'core/date'
)->timestamp(time()); |
| |
echo date
(
'm/d/y h:i:s'
,
$now
);
|
OK, that's all.