本文介绍了PHP:是否有将日期字符串转换为人类可读格式的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将"19.11.2009 14:00"之类的日期字符串转换为"2分钟","1周"或"2天"之类的日期
I want to convert a date string like "19.11.2009 14:00" into the age of it now like "for 2 minutes" or "for 1 week" or "for 2 days"
周围有一些代码吗?
推荐答案
$dateString = strtotime('19.11.2009 14.00');
$now = time();
$time = $dateString - $now;
if($time > 60 && $time < 3600) echo $time/60.' minutes remaining';
else if($time > 3600 && $time < 86400) echo $time/3600.' hours remaining';
else if($time > 86400 && $time < 604800) echo $time/86400.' days remaining';
else if($time > 604800 && $time < 18144000) echo $time/604800.' weeks remaining';
else if($time > 18144000 && $time < 217728000) echo $time/18144000.' months remaining';
else if($time > 217728000) echo $time/217728000.' years remaining';
这篇关于PHP:是否有将日期字符串转换为人类可读格式的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!