Obtain the exact current time in magento

Source: Internet
Author: User

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.








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.