【问题标题】:how to convert my TIMESTAMP to UTC timestamp in magento如何在magento中将我的TIMESTAMP转换为UTC时间戳
【发布时间】:2013-06-23 10:23:30
【问题描述】:

我发现了很多关于此的文章,但没有一个给出适当的解决方案

我当前的系统时区是 = 'asia/Kolkata'

我当前的 magento 时区是'asia/shanghai'

这给我正确的UTC时间这里系统时间是'2013-06-26 15:34:00'

   $timezone = date_default_timezone_get();
   date_default_timezone_set($timezone);

   $now = Mage::getModel('core/date')->timestamp(time());
   $current_date= date('Y-m-d H:i:s');

所以这里 $current_date = '2013-06-26 18:04:30'

但我还有另一个 mytimestamp ..... 例如:- $time = '2013-06-26 15:34:00';

   $scheduletime = '2013-06-26 15:19:00';
   $dateTimestamp = Mage::getModel('core/date')->timestamp(strtotime($scheduletime));
   $schedule_time = date('Y-m-d H:i:s',strtotime($scheduletime));

所以这里 $schedule_time = '2013-06-26 23:34:00'

所以实际上我想要的是得到这两次之间的差异,它应该是:0

【问题讨论】:

  • 时间戳是 UTC,它是您需要更正以获得正确时间的时区。
  • 谢谢你的回复....你能给我举个例子吗?
  • 如果您想在应用程序中使用 asia/Kolkata 作为您的时区,您可以在 php.ini 中设置它或在脚本顶部使用 date_default_timezone_set('asia/Kolkata')。时间戳是标准的 UTC,您提供的时区将从时间戳中添加/减去,以便为您提供该时间戳在给定时区中的日期/时间
  • 这次能不能把'2013-06-26 15:19:00'换成UTC?关于“亚洲/加尔各答”
  • strtotime('2013-06-26 15:19:00') 将为您提供在 UTC 时区中响应该日期时间的时间戳

标签: php magento datetime timezone timestamp


【解决方案1】:

试试

Mage::getSingleton('core/date')->gmtDate();

注意:UTC 和 GMT 是相等的。

【讨论】:

    【解决方案2】:

    使用 strtotime 从给定字符串(解释为本地时间)生成时间戳,并使用 gmdate 将其作为格式化的 UTC 日期返回。

    例如

    根据要求,这是一个简单的例子:

    echo gmdate('d.m.Y H:i', strtotime('2012-06-28 23:55'));
    

    或者您也可以将本地设置与商店一起使用,如下所示

    Mage::app()->getLocale()->storeDate(
                $this->getStore(),
                Varien_Date::toTimestamp($this->getCreatedAt()),
                true
            );
    

    $this->getCreatedAt() 您的数据库日期在哪里。

    【讨论】:

    • 请检查我更新的答案,一定会帮助您通过您的 magento 商店进行转换
    猜你喜欢
    • 1970-01-01
    • 2011-10-11
    • 2012-10-07
    • 2022-10-06
    • 2016-06-11
    • 2021-03-05
    • 1970-01-01
    • 2019-08-15
    • 2015-08-19
    相关资源
    最近更新 更多