PHP时间戳,如果在中午之前

PHP时间戳,如果在中午之前,php,Php,我正在尝试将特定的mesasge打印到浏览器,具体取决于我的时间戳是AM还是PM。在这种情况下,如果是在中午12点之前,那么我想重复“早上好” 以$person['StartDateTime'为单位的时间戳为2019-10-09T14:00:00 邮件总是打印出“早上好”的邮件,我在这里尝试了其他帖子,但似乎无法让它发挥作用。我试过“中午”、“12点”、“12点”等等 if ($person['StartDateTime'] < strtotime("noon")) { e

我正在尝试将特定的mesasge打印到浏览器,具体取决于我的时间戳是AM还是PM。在这种情况下,如果是在中午12点之前,那么我想重复“早上好”

以$person['StartDateTime'为单位的时间戳为2019-10-09T14:00:00

邮件总是打印出“早上好”的邮件,我在这里尝试了其他帖子,但似乎无法让它发挥作用。我试过“中午”、“12点”、“12点”等等

if ($person['StartDateTime'] < strtotime("noon"))
    {
    echo 'Meeting Time:' . $person['StartDateTime'] . '<br>';
    echo "Good morning" . '<br>';
    }
我收到了信息,但也在我的早上时间戳上——2019-10-09T10:00:00,我不应该收到


我想知道是否需要为时间戳的日期指定中午?

strotime返回时间戳。比较int值和string

我建议使用适当的参数
a
,根据时间给出am或pm

if ((new Datetime($person['StartDateTime']))->format('a') == 'am') {
  // am
} else {
  // pm
}

好的,在尝试了一些事情之后,这个案例的解决方案很简单

仅使用“A”设置日期格式,这将根据时间返回AP或PM

$starttime = date("A",strtotime(date($person['StartDateTime'])));

if ($starttime == "AM"){
echo "Good Morning" . '<br>';
}
$starttime=date(“A”),strotime(date($person['StartDateTime']));
如果($starttime==“AM”){
回声“早上好”
; }
if(strotime($person['StartDateTime']))
我得到了-解析错误:语法错误,意外的'->'(T_OBJECT_操作符)
if ((new Datetime($person['StartDateTime']))->format('a') == 'am') {
  // am
} else {
  // pm
}
$starttime = date("A",strtotime(date($person['StartDateTime'])));

if ($starttime == "AM"){
echo "Good Morning" . '<br>';
}