Regex for timestamps in php
I'm trying to take tim开发者_运维百科estamps in this format:
2009-11-16T14:05:22-08:00
and make turn them into something like
2009-11-16
How do I remove everything after the "T"?
Maybe this works:
date('Y-m-d', strtotime('2009-11-16T14:05:22-08:00'));
Assuming they're all in that format, the easiest way is:
$result = substr($timestamp,0,10);
Where timestamp is your starting timestamp and result is your modified timestamp.
You could use explode()
:
list($date) = explode('T', '2009-11-16T14:05:22-08:00');
$date
would now be '2009-11-16'
.
Since the OP tagged it as a php and regex question, I'll give him a php and regex answer:
$result = preg_replace("/T.*/", "", $timestamp);
精彩评论