将时间分为3个变量 [英] Split Time into 3 Variables

查看:92
本文介绍了将时间分为3个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个时间 7:00 am,我需要将其划分为 $ hour $ min $ ampm 。有没有简单的方法可以将其分为3个变量?

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?

推荐答案

$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];

这篇关于将时间分为3个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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