我有两个日期:
Start Date: 2007-03-24
End Date: 2009-06-26
Run Code Online (Sandbox Code Playgroud)
现在我需要通过以下形式找到这两者之间的差异:
2 years, 3 months and 2 days
Run Code Online (Sandbox Code Playgroud)
我怎么能用PHP做到这一点?
如何查找自日期时间戳以来经过的时间2010-04-28 17:25:43,最终输出文本应该像xx Minutes Ago/xx Days Ago
我想将一个$uptime秒的变量转换为天,小时,分钟和秒.
例:
$uptime = 1640467;
Run Code Online (Sandbox Code Playgroud)
结果应该是:
18 days 23 hours 41 minutes
Run Code Online (Sandbox Code Playgroud) 我想知道在我的PHP代码中复杂的if/else结构是否是一个糟糕的设计决策.有很多if语句会导致PHP运行缓慢,站点加载速度较慢等吗?
这是代码:(我不知道wordpress如何处理is_page等)
<?php
if (is_page()) {
//
if (is_page(122)) {
//subscribe page
echo "subscribe page";
}
elseif (is_page(1263)) {
//photography course
echo "photography course page";
}
elseif (is_page(array(210,184,128))) {
//210 copyright policy, 184 privacy policy, 128 contact
echo "this is either copyright policy, privacy or contact page!";
//nothing happens here, we don't need social buttons on these pages.
}
elseif (is_page(array(379,71,7,45,124,8,105,175,9,125,110))) {
//379 photo galleries, 71 car photos, 7 conceptual, 45 event photos, 124 fashion, 8 landscape, 105 misc, 175 …Run Code Online (Sandbox Code Playgroud) 如何从当天获得天差异.
tweetedAt:"2015-02-22 09:56:42".
枝条
{% for key,value in data.about %}
{% set tweets_date=(value.tweetedAt|date).date("now").format('%a') %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
我也试过了
{% set dd='now'|date('d-m-Y') %}
{% set tweets_date=(value.tweetedAt|date).dd.format('%a') %}
Run Code Online (Sandbox Code Playgroud)
最后我试了但是给出了错误:
散列键必须是带引号的字符串,数字,名称或括在括号中的表达式(值为"{"的意外标记"标点符号")
{% set difference = {{ date("m/d/Y") }}.diff(date(value.tweetedAt)) %}
{% set leftDays = difference.days %}
Run Code Online (Sandbox Code Playgroud)
错误:
<span class="small light_grey">{{tweets_date}}</span>
Impossible to invoke a method ("date") on a string variable ("June 6, 2015 01:06") in AcmeBundle
Run Code Online (Sandbox Code Playgroud)
tweet_date几天前的形式获得差异.twig/extensions通过composer 更新了我的项目安装
user@intermsh-OptiPlex-380:~$ composer require twig/extensions
Warning: This development build of composer is over …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个将接受unix时间戳并输出如下内容的函数:
4年,3个月,12天,4小时和23分钟前.
我发现的所有东西都是漂亮的日期,只是说出类似于"5年前"的东西,我不想要.
我需要like使用php在facebook消息中找到时差.
like: 2 weeks ago, 2 hr 30 mins ago, one second ago
Run Code Online (Sandbox Code Playgroud)
我的时间格式是"Ymd H:i:s"
任何人都可以帮助我吗?
我在我的nginx托管服务器上收到此错误:
Fatal error: TimeElapsedString(): Unknown property (w) in /var/www/script/system/framework.engine.php on line 51
Run Code Online (Sandbox Code Playgroud)
TimeElapsedString:
function TimeElapsedString($datetime, $full = false)
{
date_default_timezone_set('UTC');
$now = new DateTime;
$ago = new DateTime($datetime);
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7); // LINE 51
$diff->d -= $diff->w * 7;
$string = array
(
'y' => 'year',
'm' => 'month',
'w' => 'week',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
);
foreach ($string as $k => &$v)
{
if ($diff->$k)
{ …Run Code Online (Sandbox Code Playgroud) 我有一个以毫秒为单位的时间戳
$update = 1448895141168。
我正在努力将时间转换为人类可读的时间(ago)。
例如,1小时3分钟前。
我尝试在控制器中使用此功能
public function time_elapsed_string($ptime)
{
$etime = time() - $ptime;
if ($etime < 1)
{
return '0 seconds';
}
$a = array( 365 * 24 * 60 * 60 => 'year',
30 * 24 * 60 * 60 => 'month',
24 * 60 * 60 => 'day',
60 * 60 => 'hour',
60 => 'minute',
1 => 'second'
);
$a_plural = array( 'year' => 'years',
'month' => 'months',
'day' => 'days', …Run Code Online (Sandbox Code Playgroud) 正在寻找一个轻量级的功能,可以转换这个日期显示" Thu Sep 19 08:43:29 +0000 2013 "
有任何想法吗?