简体   繁体   English

格式化日期和文本

[英]Format Date and text

I need to format the pubDate to example : 我需要将pubDate格式化为example:

2 hours ago, 2 days ago or 20 hours ago .... 2小时前,2天前或20小时前....

while keeping the original date of the feed cause i tried to format before and i get all my feeds same pubDate the one i set in Date format and the date builder. 同时保留了提要的原始日期,原因是我之前尝试进行格式化,并且我将所有提要都设为相同的pubDate,即以日期格式设置的日期和日期生成器。 How can i solve this issue ? 我该如何解决这个问题?

As well i tried to format the text of my pubdate and (Read full article ) when i run pipe its perfect but in pipe output and when i call the rss file from my website i always get the format as code. 当我运行完美的管道但在管道输出中并且当我从网站调用rss文件时,我也尝试格式化pubdate和(阅读全文)的文本,当我始终以代码形式获取格式时。

You help will be greatly appreciated... 您的帮助将不胜感激...

function ShowDate($date) // $date -->  time(); value
{
$stf = 0;
$cur_time = time();
$diff = $cur_time - $date;
$phrase = array('second','minute','hour','day','week','month','year','decade');
$length = array(1,60,3600,86400,604800,2630880,31570560,315705600);

for($i =sizeof($length)-1; ($i >=0)&amp;&amp;(($no =  $diff/$length[$i])< =1); $i--); if($i < 0) $i=0; $_time = $cur_time  -($diff%$length[$i]);
$no = floor($no); if($no <> 1) $phrase[$i] .='s'; $value=sprintf("%d %s ",$no,$phrase[$i]);

if(($stf == 1)&amp;&amp;($i >= 1)&amp;&amp;(($cur_tm-$_time) > 0)) $value .= time_ago($_time);

return $value.' ago ';
}

You need to pass the date within that and you can get the desire format. 您需要在其中传递日期,然后才能获得所需的格式。

This is php function that will convert the time as a 2 hours ago and so on... 这是php函数,它将把时间转换为2小时前,依此类推...

For more further function you can check this link Date time formate 有关更多功能,您可以检查此链接日期时间格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM