简体   繁体   English

从GET参数解析日期和时间

[英]Parse Date and Time from GET Parameter

Okay so I would like to pass date and time to my script using GET. 好的,我想使用GET将日期和时间传递给脚本。 Right now it checks the exact value with the database, but it contains spaces.I want to convert 1 line eg 现在它检查与数据库的确切值,但它包含空格。我想转换1行例如

2015-03-04-03:03:34

I want to verify this string matches the timestamp in my sql table which displays like: 我想验证此字符串是否与我的sql表中显示的时间戳匹配:

2015-05-03 12:03:23

Thanks 谢谢

You can use regex with patter remove all between date and time : 您可以将regex与patter一起使用,以删除日期和时间之间的所有内容

$str = '2015-03-04-03:03:34';
$str = preg_replace('~(\d{4}-\d{2}-\d{2})(.+)(\d{2}:\d{2}:\d{2})~', '$1 $3', $str);
echo $str; // 2015-03-04 03:03:34

just use strtotime($variable) 只需使用strtotime($ variable)

http://php.net/manual/en/function.strtotime.php http://php.net/manual/en/function.strtotime.php

but be aware that you may need to modify your joining characters. 但请注意,您可能需要修改加入字符。 Forward slash (/) signifies American M/D/Y formatting, a dash (-) signifies European DMY and a period (.) signifies ISO YMD thus double check your results before you apply this solution. 正斜杠(/)表示美国M / D / Y格式,破折号(-)表示欧洲DMY,而句号(。)表示ISO YMD,因此在应用此解决方案之前请仔细检查结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM