【发布时间】:2016-06-15 22:26:31
【问题描述】:
我正在使用坚持原则,我的所有日期都已取消。当它们应该是-6(美国/芝加哥)时,它们被存储为+6。我在 America/Chicago 上有 php 和应用服务器,可以通过以下方式确认:
php > echo (new \DateTime())->format('Y-m-d h:m:i a e');
2016-03-02 02:03:47 pm America/Chicago
我在 oracle 中创建了一个表来调试:
CREATE TABLE "APP"."DATE_TEST"
( "ID" VARCHAR2(36 BYTE),
"LOCALTZ" TIMESTAMP (0) WITH LOCAL TIME ZONE,
"NOTLOCALTZ" TIMESTAMP (0) WITH TIME ZONE
)
我有一个具有以下原则映射的测试实体:
Acme\Project\Domain\Asset\Entity\DateTest:
type: entity
table: DATE_TEST
id:
id:
type: guid
generator:
strategy: none
fields:
localtz:
type: datetime
column: localtz
notlocaltz:
type: datetimetz
column: notlocaltz
我执行一些代码将数据推送到表中:
protected function execute(InputInterface $input, OutputInterface $output)
{
$test = new DateTest();
$datetime = new \DateTime();
$test->setLocalTz($datetime);
$test->setNotLocalTz($datetime);
$output->writeln($test->getId());
$output->writeln($datetime->format('Y-m-d h:i:s a'));
$output->writeln($datetime->getTimezone()->getName());
$em = $this
->getContainer()
->get('doctrine.orm.entity_manager');
$em->persist($test);
$em->flush();
$output->writeln("Test complete.");
}
输出如下
de4e5dcd-9fd6-4b5d-b9f0-6db9d1ef0582
2016-03-02 02:51:02 pm
America/Chicago
Test complete.
这就是我在数据库中看到的
de4e5dcd-9fd6-4b5d-b9f0-6db9d1ef0582 02-MAR-16 08.51.02.000000000 AM 02-MAR-16 02.51.02.000000000 PM +06:00
我已经连接了oracle session init。
当我查询数据库的当前时间时,它看起来是正确的:
SELECT SYSTIMESTAMP "NOW" FROM DUAL;
02-MAR-16 02.56.44.342456000 PM -06:00
谁能发现我做错了什么?
【问题讨论】:
-
值得检查吗?通过 php 执行此查询,如果您使用单独的客户端进行 misc db 活动,请在此处执行:
SELECT DBTIMEZONE, SESSIONTIMEZONE from dual; -
@Beege 从 php 执行那些查询对于两个查询都返回“+00:00”。好像不太对……
标签: php oracle symfony doctrine-orm doctrine