开发者

Regular expression to parse timestamp

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜