时间戳问题
我有一段代码,我想在其中显示客户每次使用折扣卡的日期和时间。客户每张卡的条目不得超过两个。但是,当我尝试以适当的格式显示两个条目时,只能正确显示较旧的时间戳格式。代码如下:
上次使用:
<?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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那么问题出在哪里呢?
So what's the problem?
您应该在 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...
我的想法是,较旧的时间戳没有通过时区推送传递,因为它落后了 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?