时间戳问题

发布于 2024-11-12 05:05:32 字数 613 浏览 2 评论 0原文

我有一段代码,我想在其中显示客户每次使用折扣卡的日期和时间。客户每张卡的条目不得超过两个。但是,当我尝试以适当的格式显示两个条目时,只能正确显示较旧的时间戳格式。代码如下:

上次使用:

    <?php

    $timestamp = mysql_to_unix($row->trans_date);  //MySql Time stamp 2011-05-31 12:49:59
    date_default_timezone_set('America/Chicago');  //Push timestamp ahead 2 hours
    $lastuse = date('F j, Y @ g:i A', $timestamp); //format date

    echo $lastuse;


    ?>
     <?php endforeach; ?>

我有两个时间戳,分别为 1306871399 和 1306864204。第一个时间戳成功处理为 2011 年 5 月 31 日下午 2:49,但第二个时间戳为 5 月 31 日, 2011 @ 12:50 PM

我不明白为什么只处理其中一个时间戳。感谢您的反馈。

I have a snippet of code where I want to show the date and time for every time a client uses a discount card. Clients can not have more than two entries per card. However, when I try to display the two entries with the appropriate formatting only the older timestamp formats properly. Code below:

Last Used:

    <?php

    $timestamp = mysql_to_unix($row->trans_date);  //MySql Time stamp 2011-05-31 12:49:59
    date_default_timezone_set('America/Chicago');  //Push timestamp ahead 2 hours
    $lastuse = date('F j, Y @ g:i A', $timestamp); //format date

    echo $lastuse;


    ?>
     <?php endforeach; ?>

I have two timestamps coming in 1306871399 and 1306864204. The first stamp successfully processes as May 31, 2011 @ 2:49 PM, but the second comes out May 31, 2011 @ 12:50 PM.

I am not understanding why only one of the timestamps are being processed. Your feedback is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

往日情怀 2024-11-19 05:05:32
  1306871399
- 1306864204
------------
=       7195

7195 seconds = 1hr 59 minutes 55 seconds

May 31/2:49pm -> May31/12:50pm is about 1hr 59 minutes apart

那么问题出在哪里呢?

  1306871399
- 1306864204
------------
=       7195

7195 seconds = 1hr 59 minutes 55 seconds

May 31/2:49pm -> May31/12:50pm is about 1hr 59 minutes apart

So what's the problem?

我不吻晚风 2024-11-19 05:05:32

您应该在 MySQL 级别格式化时间戳值以供用户显示,而不是使用 PHP 来格式化它们。这样,您就不必担心 PHP 服务器所在的时区(您参考的是芝加哥时区)。尝试使用 MySQL 日期格式< /a> 函数以字符串形式返回 MySQL 格式的时间戳,您可以显示...

You should format your timestamp values for user-display at the MySQL level, instead of using PHP to format them. That way, you don't have to worry about what timezone your PHP server is on (your reference to the Chicago timezone). Try using the MySQL Date Format function to return a MySQL formatted timestamp as a string you can display...

束缚m 2024-11-19 05:05:32

我的想法是,较旧的时间戳没有通过时区推送传递,因为它落后了 2 小时。确保您的代码通过它运行这两个值。

如果不是这样..您的托管提供商最近是否发生了变化?服务器时间与本地时间可能是一个问题?

My thinking is that the older timestamp is not being passed through the timezone push, as it is 2 hours behind. Make sure your code is running both values through it.

If that's not it.. has your hosting provider changed recently? Server-time vs. Local-time could be an issue?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文