如何将日期转换成相同格式?

问题描述

| 我想获得$ registratiedag并额外数天,但是我总是被困在它需要是UNIX时间戳的事实上吗?我做了一些谷歌搜索,但我真的不明白。 我希望有人可以帮助我解决这个问题。这就是我到目前为止所得到的。
$registratiedag = $oUser[\'UserRegisterDate\'];
$today = strtotime(\'$registratiedag + 6 days\');

echo $today;            
echo $registratiedag;

echo date(\'Y-m-d\',$today);
strtotime(\'$registratiedag + 6 days\');
部分显然有问题,因为我总是得到1970-01-01     

解决方法

您可能想要这样:
// Store as a timestamp
$registratiedag = strtotime($oUser[\'UserRegisterDate\']);
$new_date = strtotime(\'+6 days\',$registratiedag);

// You\'ll need to format for printing $new_date
echo date(\'Y-m-d\',$new_date);

// I think you want to compare $new_date against
// today\'s date. I\'d recommend a string comparison here,// As time() includes the time as well
// time() is implied as the second argument to date,// But we\'ll put it anyways just to be clearer 
if( date(\'Y-m-d\',$new_date) == date(\'Y-m-d\',time()) ) {
  // The dates are equal,do something here
}
else if($new_date < time()) {
  // if the new date is earlier than today
}
// etc.
首先将
$registratiedag
转换为时间戳,然后加上6天 编辑:您可能应该将
$today
更改为不太误导的内容,例如
$modified_date
或类似内容     ,尝试: $ today = strtorime($ registratiedag); $ today + = 86400 * 6; // 1天* 6天 至少您的问题之一是PHP无法将变量扩展为单引号。     ,
$today = strtotime(\"$registratiedag + 6 days\"); 
//use double quotes and not single quotes when embedding a php variable in a string
    ,如果要将变量“ 3”的值直接包含在作为参数“ 8”传递的文本中,则必须用“ 9”而不是“ 10”将参数括起来。     

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...