1 Star 1 Fork 2

alen / magento

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
在Magento 2中獲取當前商店日期和時間的步驟.txt 1000 Bytes
一键复制 编辑 原始数据 按行查看 历史
在Magento 2中獲取當前商店日期和時間的步驟
創建Data.php文件 並使用此代碼。
<?php
namespace Meetanshi\Module\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
class Data extends AbstractHelper
{
protected $timezoneInterface;
public function __construct(Context $context, TimezoneInterface $timezoneInterface)
{
$this->timezoneInterface = $timezoneInterface;
parent::__construct($context);
}
public function getStoreDateTime()
{
$formatDate = $this->timezoneInterface->formatDate();
// you can also get format wise date and time
$dateTime = $this->timezoneInterface->date()->format('Y-m-d H:i:s');
$date = $this->timezoneInterface->date()->format('Y-m-d');
$time = $this->timezoneInterface->date()->format('H:i');
return $dateTime;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/alen2017/magento.git
git@gitee.com:alen2017/magento.git
alen2017
magento
magento
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891