您如何解释新的\DateTime('0000-00-00 00:00:00')的结果? [英] How do you explain the result for a new \DateTime('0000-00-00 00:00:00')?

查看:651
本文介绍了您如何解释新的\DateTime('0000-00-00 00:00:00')的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个测试代码:

<?php

ini_set('date.timezone', 'Europe/London');    
$dt = new \DateTime('0000-00-00 00:00:00');

var_dump($dt);

这提供:

object(DateTime)[1]
  public 'date' => string '-0001-11-30 00:00:00' (length=20)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/London' (length=13)

虽然这不是有效的日期。我不明白返回的价值,特别是月份...可以解释吗?

Whereas this is not a valid date. I don't understand the returned value, especially the month... can you explain?

推荐答案

你在这里看到两个效果。第一个是您使用一种可以以多种形式写入日期的方式:

You are seeing two effects here. The first one is that you use a way of writing for a date that can be written in multiple forms:

0000-01-01 same as  0000-01-01
0000-01-00 same as -0001-12-31
0000-00-01 same as -0001-12-01
0000-00-00 same as -0001-11-30

所以在日期本身你已经指定了11月30日-1。

So by the date itself, you already specify the 30th November -1.

现在有9分21秒的时差偏差。那是因为与当时在巴黎/法国的UTC相比,在1911年3月10日23:51:38/39当地时间发生了变化。

Now there's the time offset left that differs about the 9 minutes and 21 seconds. That is because of a change in the clock compared to UTC in Paris/France that happened 10 Mar 1911 23:51:38/39 local time.

我修改了您的代码示例,并介绍了欧洲/巴黎设置,因为它具有它,这是一个角色。这段代码也是从UTC( Z )以秒为单位的偏移量,这是你正在寻找的:

I modified your code example a bit and introduced the Europe/Paris setting as you have it, which is playing a role. This code is telling as well the offset in seconds from UTC (Z) which is what you're looking for:

$dt = new DateTime('0000-00-00 00:00:00', new DateTimeZone('Europe/Paris'));
printf("%s secs offset from UTC\n", $dt->format('r T (e) Z'));

我更改日期有点

Fri, 10 Mar 1911 23:51:38 +0009 PMT (Europe/Paris) 561 secs offset from UTC
                                                   ^^^

一秒钟后:

Fri, 10 Mar 1911 23:51:39 +0000 WET (Europe/Paris) 0 secs offset from UTC




当地标准时间即将达到
1911年3月11日星期六00:01:00时钟向后转0:09:21小时到
1911年3月10日星期五23 :51:39本地标准时间。

When local standard time was about to reach Saturday, 11 March 1911, 00:01:00 clocks were turned backward 0:09:21 hours to Friday, 10 March 1911, 23:51:39 local standard time instead.

这是561秒。参考:巴黎的时钟变化 - 时间变化日期在1911年时区更改和夏令时开始/结束日期之间的年份1900和1924年

That are 561 Secs. Reference: Clock changes in Paris - Time change dates in 1911 and Time zone changes and daylight saving time start/end dates between year 1900 and 1924.

这篇关于您如何解释新的\DateTime('0000-00-00 00:00:00')的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆