reference/datetime/datetime/settimestamp.xml
02ff7fef5b34cf8f5395180d9d39fb64d9398d00
...
...
@@ -1,6 +1,5 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="datetime.settimestamp" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>DateTime::setTimestamp</refname>
...
...
@@ -11,19 +10,27 @@
11
10
<refsect1 role="description">
12
11
&reftitle.description;
13
12
<para>&style.oop;</para>
14
-
<methodsynopsis role="oop">
13
+
<methodsynopsis role="DateTime">
15
14
<modifier>public</modifier> <type>DateTime</type><methodname>DateTime::setTimestamp</methodname>
16
-
<methodparam><type>int</type><parameter>unixtimestamp</parameter></methodparam>
15
+
<methodparam><type>int</type><parameter>timestamp</parameter></methodparam>
17
16
</methodsynopsis>
18
17
<para>&style.procedural;</para>
19
-
<methodsynopsis role="procedural">
18
+
<methodsynopsis>
20
19
<type>DateTime</type><methodname>date_timestamp_set</methodname>
21
20
<methodparam><type>DateTime</type><parameter>object</parameter></methodparam>
22
-
<methodparam><type>int</type><parameter>unixtimestamp</parameter></methodparam>
21
+
<methodparam><type>int</type><parameter>timestamp</parameter></methodparam>
23
22
</methodsynopsis>
24
23
<para>
25
24
Sets the date and time based on an Unix timestamp.
26
25
</para>
26
+
<para>
27
+
Like <methodname>DateTimeImmutable::setTimestamp</methodname> but works with
28
+
<classname>DateTime</classname>.
29
+
</para>
30
+
<para>
31
+
The procedural version takes the <classname>DateTime</classname> object as
32
+
its first argument.
33
+
</para>
27
34
</refsect1>
28
35

29
36
<refsect1 role="parameters">
...
...
@@ -31,10 +38,12 @@
31
38
<variablelist>
32
39
&date.datetime.description.modified;
33
40
<varlistentry>
34
-
<term><parameter>unixtimestamp</parameter></term>
41
+
<term><parameter>timestamp</parameter></term>
35
42
<listitem>
36
43
<para>
37
44
Unix timestamp representing the date.
45
+
Setting timestamps outside the range of &integer; is possible by using
46
+
<methodname>DateTimeImmutable::modify</methodname> with the <literal>@</literal> format.
38
47
</para>
39
48
</listitem>
40
49
</varlistentry>
...
...
@@ -44,85 +53,17 @@
44
53
<refsect1 role="returnvalues">
45
54
&reftitle.returnvalues;
46
55
<para>
47
-
&date.datetime.return.modifiedobjectorfalseforfailure;
56
+
&date.datetime.return.modifiedobject;
48
57
</para>
49
58
</refsect1>
50
59

51
-
<refsect1 role="examples">
52
-
&reftitle.examples;
53
-
<example>
54
-
<title><function>DateTime::setTimestamp</function> example</title>
55
-
<para>&style.oop;</para>
56
-
<programlisting role="php">
57
-
<![CDATA[
58
-
<?php
59
-
$date = new DateTime();
60
-
echo $date->format('U = Y-m-d H:i:s') . "\n";
61
-

62
-
$date->setTimestamp(1171502725);
63
-
echo $date->format('U = Y-m-d H:i:s') . "\n";
64
-
?>
65
-
]]>
66
-
</programlisting>
67
-
<para>&style.procedural;</para>
68
-
<programlisting role="php">
69
-
<![CDATA[
70
-
<?php
71
-
$date = date_create();
72
-
echo date_format($date, 'U = Y-m-d H:i:s') . "\n";
73
-

74
-
date_timestamp_set($date, 1171502725);
75
-
echo date_format($date, 'U = Y-m-d H:i:s') . "\n";
76
-
?>
77
-
]]>
78
-
</programlisting>
79
-
&examples.outputs.similar;
80
-
<screen>
81
-
<![CDATA[
82
-
1272508903 = 2010-04-28 22:41:43
83
-
1171502725 = 2007-02-14 20:25:25
84
-
]]>
85
-
</screen>
86
-
</example>
87
-
</refsect1>
88
-

89
-
<refsect1 role="notes">
90
-
&reftitle.notes;
91
-
<para>
92
-
Using the Unix timestamp format to construct a new <type>DateTime</type>
93
-
object is an alternative when using PHP 5.2, as shown in the example below.
94
-
</para>
95
-
<example>
96
-
<title>
97
-
<function>DateTime::setTimestamp</function> alternative in PHP 5.2
98
-
</title>
99
-
<programlisting role="php">
100
-
<![CDATA[
101
-
<?php
102
-
$ts = 1171502725;
103
-
$date = new DateTime("@$ts");
104
-
echo $date->format('U = Y-m-d H:i:s') . "\n";
105
-
?>
106
-
]]>
107
-
</programlisting>
108
-
&example.outputs.similar;
109
-
<screen>
110
-
<![CDATA[
111
-
1171502725 = 2007-02-14 20:25:25
112
-
]]>
113
-
</screen>
114
-
</example>
115
-
</refsect1>
116
-

117
60
<refsect1 role="seealso">
118
61
&reftitle.seealso;
119
62
<simplelist>
120
-
<member><function>DateTime::getTimestamp</function></member>
63
+
<member><function>DateTimeImmutable::setTimestamp</function></member>
121
64
</simplelist>
122
65
</refsect1>
123
-

124
66
</refentry>
125
-

126
67
<!-- Keep this comment at the end of the file
127
68
Local variables:
128
69
mode: sgml
129
70