将单独的月,日和年值转换为时间戳 [英] Converting separate month, day and year values into a timestamp

查看:145
本文介绍了将单独的月,日和年值转换为时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个月值(1-12),日值(1-31)和一个年值(2010,2011,2012)。我还有一个小时值和一个小时的值。

I have a month value (1-12), day value (1-31), and a year value (2010,2011,2012). I also have a hour value and a minute value.

如何将这个值赋给 strtotime()方式可以将其转换为时间戳?

How can I give this to strtotime() in a way it can convert it to a timestamp?

推荐答案

给定变量 $ year $ month $ day $ hour $ minute 你可以做:

Given the variables $year $month $day $hour $minute you can do:

strtotime("$year-$month-$day $hour:$minute");

请小心用在这种情况下,从来没有使用'

Be careful to enclose the variables with ", never in this case with '.

更新(感谢@Clockwork和@Tadeck的评论):

如果有一个变量 $ timeofday 表示<一天(即AM或PM),
那么您可以用以下方法解析:

In case there is a variable $timeofday that represents the time of day (i.e. AM or PM), then you can parse it this with:

strtotime("$year-$month-$day $hour:$minute$timeofday");

说,只需将该变量附加到文本的末尾。

that is to say, just attach that variable to the end of the text.

这篇关于将单独的月,日和年值转换为时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆