开发者

Regular expression to parse timestamp

开发者 https://www.devze.com 2023-03-30 21:39 出处:网络
Timestamp is in this f开发者_StackOverflow中文版ormat date(\'m-d-Y H:i:s A\') which will result 08-26-2011 16:00:25 PM.

Timestamp is in this f开发者_StackOverflow中文版ormat date('m-d-Y H:i:s A') which will result 08-26-2011 16:00:25 PM.

I need a regular expression to parse a file with time stamps starting with last week and last month, ignore previous time stamps. Basically something like this:

if(preg_match("/TimestampsWithinLastWeek+String/", $match))
{
   //Do something
}


Regex is not the right tool for this, use strtotime() instead:

if( strtotime( $dateString ) > strtotime( "Monday last week" ) ) {
    //Do something
}


Try to use either date_parse or strtotime instead of regular expressions... the overhead will be much less.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号