使用php怎么将日期格式转换成多少天前-创新互联

这篇文章主要介绍了使用php怎么将日期格式转换成多少天前,创新互联网站建设公司,小编觉得不错,现在分享给大家,也给大家做个参考,一起跟随创新互联网站建设公司,小编来看看吧!

创新互联公司主营玉环网站建设的网络公司,主营网站建设方案,APP应用开发,玉环h5小程序设计搭建,玉环网站营销推广欢迎玉环等地区企业咨询

php有什么用

php是一个嵌套的缩写名称,是英文超级文本预处理语言,它的语法混合了C、Java、Perl以及php自创新的语法,主要用来做网站开发,许多小型网站都用php开发,因为php是开源的,从而使得php经久不衰。

具体如下:

// convert a date into a string that tells how long ago
// that date was.... eg: 2 days ago, 3 minutes ago.
function ago($d) {
 $c = getdate();
 $p = array('year', 'mon', 'mday', 'hours', 'minutes', 'seconds');
 $display = array('year', 'month', 'day', 'hour', 'minute', 'second');
 $factor = array(0, 12, 30, 24, 60, 60);
 $d = datetoarr($d);
 for ($w = 0; $w < 6; $w++) {
 if ($w > 0) {
  $c[$p[$w]] += $c[$p[$w-1]] * $factor[$w];
  $d[$p[$w]] += $d[$p[$w-1]] * $factor[$w];
 }
 if ($c[$p[$w]] - $d[$p[$w]] > 1) { 
  return ($c[$p[$w]] - $d[$p[$w]]).' '.$display[$w].'s ago';
 }
 }
 return '';
}
// you can replace this if need be. 
// This converts my dates returned from a mysql date string 
// into an array object similar to that returned by getdate().
function datetoarr($d) {
 preg_match("/([0-9]{4})(\\-)([0-9]{2})(\\-)([0-9]{2})([0-9]{2})(\\:)([0-9]{2})(\\:)([0-9]{2})/",$d,$matches);
 return array( 
 'seconds' => $matches[10], 
 'minutes' => $matches[8], 
 'hours' => $matches[6], 
 'mday' => $matches[5], 
 'mon' => $matches[3], 
 'year' => $matches[1], 
 );
}

以上就是创新互联网站建设公司,小编为大家收集整理的使用php怎么将日期格式转换成多少天前,如何觉得创新互联建站的内容还不错,欢迎将创新互联建站推荐给身边好友。

本文题目:使用php怎么将日期格式转换成多少天前-创新互联
网站路径:https://www.cdcxhl.com/article4/hodie.html

成都网站建设公司_创新互联,为您提供移动网站建设网站制作面包屑导航品牌网站建设响应式网站自适应网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

手机网站建设