-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathstrtotime.xml
executable file
·206 lines (196 loc) · 6.4 KB
/
strtotime.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 5c951013ca04161992efed8b86fb40f55669958e Maintainer: Avenger Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<!-- splitted from ./en/functions/datetime.xml, last change in rev 1.8 -->
<refentry xml:id="function.strtotime" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>strtotime</refname>
<refpurpose>将任何英文文本日期时间描述解析为 Unix 时间戳</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>int</type><type>false</type></type><methodname>strtotime</methodname>
<methodparam><type>string</type><parameter>datetime</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>baseTimestamp</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<simpara>
本函数期望接受包含英文日期格式的字符串并尝试将其解析为
Unix 时间戳(自 January 1 1970 00:00:00 UTC 起的秒数),其值跟
<parameter>baseTimestamp</parameter> 参数给出的时间相关,如果没有提供
<parameter>baseTimestamp</parameter> 参数则为当前时间。在<link
linkend="datetime.formats">日期和时间格式</link>中定义了日期字符串解析,并且有几个微秒的注意事项,强烈建议查看完整详细信息。
</simpara>
<warning>
<para>
本函数返回的 Unix 时间戳不包含时区信息,为了实现对日期/时间信息进行计算,推荐使用功能更强大的
<classname>DateTimeImmutable</classname>。
</para>
</warning>
<para>
本函数的每个参数都使用默认时区,除非在该参数指定了时区。注意不要在每个参数中使用不同的时区,除非是故意的。参考
<function>date_default_timezone_get</function> 获取定义默认时区的各种方法。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>datetime</parameter></term>
<listitem>
<para>&date.formats.parameter;</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>baseTimestamp</parameter></term>
<listitem>
<para>
时间戳,用作计算相对日期的基础。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
成功则返回时间戳,否则返回 &false;。
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
&date.timezone.errors.description;
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
现在 <parameter>baseTimestamp</parameter> 允许为 null。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>strtotime</function> 例子</title>
<programlisting role="php">
<![CDATA[
<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>失败检查</title>
<programlisting role="php">
<![CDATA[
<?php
$str = 'Not Good';
if (($timestamp = strtotime($str)) === false) {
echo "The string ($str) is bogus";
} else {
echo "$str == " . date('l dS \o\f F Y h:i:s A', $timestamp);
}
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
在这种情况下,“相对”日期还意味着,如果未提供日期/时间的特定组成部分,则将从 <parameter>baseTimestamp</parameter>
逐字获取。也就是说如果在 2022 年 5 月 31 日运行 <code>strtotime('February')</code>,将被解释为
<literal>31 February 2022</literal>,它将溢出到 <literal>3 March</literal> 的时间戳。(在闰年,应该是
<literal>2 March</literal>。)使用 <code>strtotime('1 February')</code> 或者
<code>strtotime('first day of February')</code> 可以避免这个问题。
</para>
</note>
<note>
<para>
如果指定的年份位数是两位数字,则其值 0-69 表示 2000-2069,70-99 表示 1970-1999。参阅下面的注释了解
32 位系统上可能的差异(结束日期可能是 2038-01-19 03:14:07)。
</para>
</note>
<note>
<para>
时间戳的有效范围通常从 Fri, 13 Dec 1901 20:45:54 UTC
到 Tue, 19 Jan 2038 03:14:07 UTC(这些日期对应 32
位有符号整数的最小值和最大值)。
</para>
<para>
在 64 位的 PHP 版本中,时间戳的有效范围实际上是无限的,因为
64 位在任一方向上都可以代表大约 2930 亿年。
</para>
</note>
<note>
<para>
不建议使用此函数对日期进行数学运算。推荐使用
<methodname>DateTime::add</methodname> 和
<methodname>DateTime::sub</methodname> 函数。
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><classname>DateTimeImmutable</classname></member>
<member><methodname>DateTimeImmutable::createFromFormat</methodname></member>
<member><link linkend="datetime.formats">日期和时间格式</link></member>
<member><function>checkdate</function></member>
<member><function>strptime</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->