开发者

Regex for timestamps in php

开发者 https://www.devze.com 2022-12-12 04:17 出处:网络
I\'m trying to take tim开发者_运维百科estamps in this format: 2009-11-16T14:05:22-08:00 and make turn them into something like

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);
0

精彩评论

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

关注公众号