Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 错误日期广告_Php_Date_Datetime - Fatal编程技术网

Php 错误日期广告

Php 错误日期广告,php,date,datetime,Php,Date,Datetime,我正试图从Active Directory中获取'passwordLastSet'属性,但它会在1小时内返回 返回:11-05-2018 10:30:07 应为:11-05-2018 11:30:07(实时上次密码更改) Active Directory服务器(Windows server 2012)与PHP服务器(我的开发计算机)同时运行 我的PHP时区设置为Europe/Lisbon,date函数返回正确的时间 我正在使用LDAP工具 我的问题是: $user = $ldap-&g

我正试图从Active Directory中获取
'passwordLastSet'
属性,但它会在1小时内返回

返回:
11-05-2018 10:30:07

应为:
11-05-2018 11:30:07
(实时上次密码更改)

Active Directory服务器(Windows server 2012)与PHP服务器(我的开发计算机)同时运行

我的PHP时区设置为Europe/Lisbon,date函数返回正确的时间

我正在使用
LDAP工具

我的问题是:

    $user = $ldap->buildLdapQuery()
        ->select(['username', 'emailAddress', 'firstName', 'lastName', 'passwordLastSet'])
        ->fromUsers()
        ->where(['username' => $username])
        ->getLdapQuery()
        ->getSingleResult();
返回:

date_format($user->passwordLastSet, 'd-m-Y H:i:s')
有人能帮我吗

谢谢

您可以使用以下示例:

 $data= "2010-03-21";
 $newDate = date("d-m-Y", strtotime($data));
var\u dump($user->passwordLastSet)
提供:

object(DateTime)#52 (3) {
    ["date"]=> string(26) "2018-05-11 10:30:07.000000"
    ["timezone_type"]=> int(1)
    ["timezone"]=> string(6) "+00:00"
}
这告诉我们,
$user->passwordLastSet
是一个包含
UTC
时区的对象,因此当您格式化它时,它只输出该值-并且由于您当前使用夏令时(
UTC+1
),因此它落后了一个小时

在输出之前,您需要更改
DateTime
对象上的时区,如下所示:

$user->passwordLastSet->setTimeZone(new DateTimezone('Europe/Lisbon'));
echo $user->passwordLastSet->format('d-m-Y H:i:s');

它返回指定时区的正确时间;您当前的时区是GMT+1(夏季时间)-您正在跳过:
date\u format()
call中的时区。@CD001我已经在配置文件中定义了这个:date\u default\u timezone\u set(“Europe/Lisbon”);这应该适用于整个站点,对吗?如果你
var\u dump($user->passwordLastSet)
,你会得到什么?了解您从Active Directory中实际获得的内容会很有帮助。@CD001获取此信息:
object(DateTime)#52(3){[“date”]=>string(26)“2018-05-11 10:30:07.000000”[“timezone\u type”]=>int(1)[“timezone”=>string(6)+00:00”}
Right-您从Active Directory获得的时区是
GMT
,但
date\u format
不知道这一点,要了解我的意思,请尝试:
$arDate=new DateTime('2018-05-11 10:30:07',new DateTime('UTC')$arDate->setTimeZone(新日期时区(“欧洲/里斯本”);echo$arDate->format('r')