php strtotime() 一些帮助
我正在获取信用卡详细信息,并在两个表单字段中获取到期日期,一个用于到期月份,一个用于到期年份,我想将到期日期存储为时间戳。 strtotime("05/2010")
会创建时间戳吗?还是我还需要度过一天,或者有其他选择吗?
谢谢
I am taking credit card details and I am taking the expiration date in two form field, one for the expiration month and one for the expiration year, I am wanting to store the expiration date as timestamp. Will strtotime("05/2010")
create a time stamp or do I need to pass a day as well or is there an alternative?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,那是行不通的,
strtotime("05/2010")
将返回false
。您还需要指定一天。但是,这种情况存在歧义,因为strtotime("01/05/2010")
是指 2010 年 5 月 1 日还是 2010 年 1 月 5 日?等你可能最好使用 mktime() 而不是
strtotime ()
,因为您可以明确指出哪些部分是月份和年份,然后只需传递 1 作为日期。No, that won't work,
strtotime("05/2010")
will returnfalse
. You would need to specify a day as well. However, there's ambiguity in that case as doesstrtotime("01/05/2010")
mean the 1st of May 2010, or the 5th of January 2010? etcYou're probably better using mktime() instead of
strtotime()
, since you can explicitly state which parts are the month and year, and then just pass 1 as the day.更好地使用 mktime():
mktime(0, 0, 0, $month, 1, $year)
这将生成给定年份中给定月份第一天的时间戳,时间为 00:00:00。
Better use mktime():
mktime(0, 0, 0, $month, 1, $year)
This will generate a timestamp for the 1st day of the given month in the given year with the time 00:00:00.
如果您传递“1”作为日期,您的编程将导致信用卡在该月的第一天到期。这不是标准做法,即该卡在该月的最后一天到期。可以使用 PHP date('t') 找到该月的最后一天。
也许您会看到这篇文章(希望如此)。它教授了有关在 PHP 中处理 DATETIME 值所需了解的大部分内容。
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
最好的问候,~Ray
If you pass "1" as the day, your programming will cause the credit card to expire on the first of the month. This is not the standard practice, which is to have the card expire on the last day of the month. The last of the month can be found with PHP date('t').
Maybe this article will be visible to you (hope so). It teaches most of what you need to know about handling DATETIME values in PHP.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
Best regards, ~Ray