date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
Related Articles
- Auto-detect timezones, time zone offsets and daylight saving in javascript (javascriptkata.com)
- Timezones – Thomas Blackburn (itunes.apple.com)
- TheFind and Magento Partner on Better Data and More Leads for Online Merchants (eon.businesswire.com)
- Extending the Magento API (nofluffjuststuff.com)
- Polaroid: A Free Magento Theme For Your eCommerce Website (smashingmagazine.com)
- OrderMotion’s Connector for Magento eCommerce Platform Brings High-Volume Online Merchants a New Level of Sophistication (eon.businesswire.com)
- Magento Partners With Celebros to Bring Semantic SiteSearch to the Magento eCommerce Platform (eon.businesswire.com)
- Handling Date/Times and timezones (tech.bluesmoon.info)
- 30 Essential Free Magento Extensions (freelancedesignerindelhi.wordpress.com)
- eBay takes over Magento: The end of an era (romanzenner.com)
- E-Commerce made easy: Magento (xemion.com)
Mage::app()->getLocale()->date(null, null, null, false)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
LikeLike
[…] Magento: Get the current date and time according to the … – ← Magento: change system timezone. Magento … The offset will always be your local timezone in PHP (should be +00:00 as Magento sets UTC explicitly) … my web server has set to EST and has show me time with 4 hour ahead. […]
LikeLike
The above code simply adds an offset to the UTC time which makes the time wrong. If your timezone is +4:00 then time() (i.e. now) will actually be four hours in the future! It’s OK if all you’re doing is printing the date but if you’re storing the value of Mage::getModel(‘core/date’)->timestamp(time()) to a database (which should be in UTC) the time will be wrong. You can see this with the following code:
timestamp(time()));
?>
The offset will always be your local timezone in PHP (should be +00:00 as Magento sets UTC explicitly) regardless of what you set in Magento config.
This code is better:
getLocale()->storeDate(Mage::app()->getStore(), null, true)->toString(‘Y-MM-dd HH:mm:ss’);
?>
It is timezone, daylight saving and locale aware and uses UTC time internally.
LikeLike
Re: phpbugs
Thanks, using it to post a notification on my site when store is closed (we’re a restaurant).
Just a note to anyone copying and pasting your code, the apostrophe is not the correct character in your code, it’s displayed now as a single quote character (probably automatically done by the comment system). So just retype the apostrophes when using the code.
Thanks!
LikeLike
Hey………. it work.
my web server has set to EST and has show me time with 4 hour ahead.
But my using the above code it gave me correct time as per the timezone.
Thanks a lot for your valuable post.
LikeLike
sounds good, I’ll try the code right now, thanks a lot
LikeLike
Hy, you can help me? I wish I could change the welcome message depending on the time in mangeto. Ex.: good morning, good evening …
do you have any idea?
thank you
LikeLike
What about using the below code:
<?php
$hour = date(“H”, Mage::getModel(‘core/date’)->timestamp(time()));
if(hour < 12){
return “good morning”;
}elseif(hour > 11 && hour < 15){
return “good afternoon”;
}elseif(hour > 15){
return “good evening”;
}
?>
LikeLike