Split Time into 3 Variables

前端 未结 5 1846
鱼传尺愫
鱼传尺愫 2021-01-21 17:48

I have a time \"7:00 am\" that I need to split into $hour, $min, $ampm. Is there an easy way that I can split this in to 3 variables?

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-21 17:53

    $yourtime = "7:00 am";
    preg_match("/([0-9]{1,2}):([0-9]{1,2}) ([a-zA-Z]+)/", $yourtime, $match);
    $hour = $match[1];
    $min = $match[2];
    $ampm = $match[3];
    

提交回复
热议问题