【问题标题】:Php scripts displays different date and time from my laptop date and time i want scripts to display my date and timePHP 脚本显示的日期和时间与我的笔记本电脑日期和时间不同 我希望脚本显示我的日期和时间
【发布时间】:2020-10-05 20:31:33
【问题描述】:

这是我的日期和时间配置文件。

请问,我还可以在哪里编辑以从我的 PC 中获取日期和时间?

$config['time_reference'] = 'local';

所以我有这个打印报告的脚本,但日期和时间与我的电脑日期和时间不匹配。代码如下

 <div class="panel-body">
                    <div id="printableArea" style="margin-left:2px;">
                        <div class="text-center">
                            {company_info}
                            <h3> {company_name} </h3>
                            <h4 >{address} </h4>
                            {/company_info}
                            <h4> <?php echo display('print_date') ?>: <?php echo date("d/m/Y h:i:s"); ?> </h4>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-bordered table-striped table-hover">
                                <thead>
                                    <tr>
                                        <th><?php echo display('sales_date') ?></th>
                                        <th><?php echo display('invoice_no') ?></th>
                                        <th><?php echo display('customer_name')?></th>
                                        <th><?php echo display('total_amount')?></th>
                                    </tr>
                                </thead>
                                <tbody>
                                <?php

【问题讨论】:

    标签: php date time timezone


    【解决方案1】:

    这是获取本地日期/时间的最快方法

    $dateTime = new DateTime("NOW", new DateTimeZone('Europe/Amsterdam'));
    
    echo $dateTime->format("d/m/yyyy H:i:s");
    

    另外,您可以使用 PHP 中的 localtime

    希望这会有所帮助!

    【讨论】:

    • 谢谢@Ahmad,我会试试看,但是我应该把这段代码放在哪里来获取所有脚本的日期时间。
    • @Simon 我没有看到你的代码库所以不能说在哪里,但主要检查你是否有一个共享的文件或者你总是包含它的东西,或者它总是显示并添加这个代码 sn- p 那里。希望这能给出一个想法,因为这很难说:)
    • ohk @Ahmad buh 我想知道我所有 scipts 的日期和时间,所以先生,我该怎么办
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多