1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-24 15:12:20 +01:00
Files
2025-11-06 09:04:46 +08:00

247 lines
7.2 KiB
XML
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 3a8c3e77df070a046c9d5b56b68926ca2d7e5ee3 Maintainer: dallas Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.idate" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>idate</refname>
<refpurpose>将本地日期/时间格式化为整数</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>int</type><type>false</type></type><methodname>idate</methodname>
<methodparam><type>string</type><parameter>format</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>timestamp</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
使用明确的 int 类型 <parameter>timestamp</parameter>
或者当前本地时间(如果没有明确时间戳),根据明确的格式化字符串返回格式化后的数字。换句话说,<parameter>timestamp</parameter>
是可选的,默认值是 <function>time</function> 的值。
</para>
<para>
<function>date</function> 不同,<function>idate</function>
只接受一个字符作为 <parameter>format</parameter> 的参数。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>format</parameter></term>
<listitem>
<para>
<table>
<title><parameter>format</parameter> 参数字符串仅识别以下字符</title>
<tgroup cols="2">
<thead>
<row>
<entry><parameter>format</parameter> 字符</entry>
<entry>说明</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>B</literal></entry>
<entry>Swatch Beat/互联网时间</entry>
</row>
<row>
<entry><literal>d</literal></entry>
<entry>月份中的第几天</entry>
</row>
<row>
<entry><literal>h</literal></entry>
<entry>小时12 小时制)</entry>
</row>
<row>
<entry><literal>H</literal></entry>
<entry>小时24 小时制)</entry>
</row>
<row>
<entry><literal>i</literal></entry>
<entry>分钟</entry>
</row>
<row>
<entry><literal>I</literal>(大写 i</entry>
<entry>如果启用夏令时则返回 <literal>1</literal>,否则返回 <literal>0</literal></entry>
</row>
<row>
<entry><literal>L</literal>(大写 l</entry>
<entry>如果是闰年则返回 <literal>1</literal>,否则返回 <literal>0</literal></entry>
</row>
<row>
<entry><literal>m</literal></entry>
<entry>月份的数字</entry>
</row>
<row>
<entry><literal>N</literal></entry>
<entry>ISO-8601 格式的周几(<literal>1</literal> 表示周一到 <literal>7</literal> 表示周日)</entry>
</row>
<row>
<entry><literal>o</literal></entry>
<entry>ISO-8601 格式的年份4位</entry>
</row>
<row>
<entry><literal>s</literal></entry>
<entry>秒数</entry>
</row>
<row>
<entry><literal>t</literal></entry>
<entry>本月的总天数</entry>
</row>
<row>
<entry><literal>U</literal></entry>
<entry>自 Unix 纪元January 1 1970 00:00:00 GMT起的秒数——这和 <function>time</function> 相同</entry>
</row>
<row>
<entry><literal>w</literal></entry>
<entry>周几(<literal>0</literal> 是周日)</entry>
</row>
<row>
<entry><literal>W</literal></entry>
<entry>ISO-8601 格式的年份中第几个星期,每星期从星期一开始</entry>
</row>
<row>
<entry><literal>y</literal></entry>
<entry>年份1 或 2 位数字——见下面说明)</entry>
</row>
<row>
<entry><literal>Y</literal></entry>
<entry>年份4 位数字)</entry>
</row>
<row>
<entry><literal>z</literal></entry>
<entry>年份中的第几天</entry>
</row>
<row>
<entry><literal>Z</literal></entry>
<entry>以秒为单位的时差</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</listitem>
</varlistentry>
&date.timestamp.description;
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
成功时返回 <type>int</type>&return.falseforfailure;
</para>
<para>
由于 <function>idate</function> 始终返回不以“0”开头的
<type>int</type>,因此 <function>idate</function>
返回的数字可能位数要比期望的小。查看以下示例。
</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.2.0</entry>
<entry>
添加 <literal>N</literal>ISO-8601 格式的周几)和
<literal>o</literal>ISO-8601 格式的年份)格式字符。
</entry>
</row>
<row>
<entry>8.0.0</entry>
<entry>
现在 <parameter>timestamp</parameter> 允许为 null。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>idate</function> 示例</title>
<programlisting role="php">
<![CDATA[
<?php
$timestamp = strtotime('1st January 2004'); // 1072915200
// 下面以两位数字格式打印年份,但是因为
// 以“0”打头因此只会打印“4”
echo idate('y', $timestamp) . "\n";
$timestamp = strtotime('1st January 2024'); // 1704067200
echo idate('y', $timestamp);
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
4
24
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>DateTimeInterface::format</methodname></member>
<member><function>date</function></member>
<member><function>getdate</function></member>
<member><function>time</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
-->