This repository was archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathclass.mongodate.html
134 lines (86 loc) · 6.75 KB
/
class.mongodate.html
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>The MongoDate class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />
</head>
<body class="docs"><div class="navbar navbar-fixed-top">
<div class="navbar-inner clearfix">
<ul class="nav" style="width: 100%">
<li style="float: left;"><a href="mongocode.tostring.html">« MongoCode::__toString</a></li>
<li style="float: right;"><a href="mongodate.construct.html">MongoDate::__construct »</a></li>
</ul>
</div>
</div>
<div id="breadcrumbs" class="clearfix">
<ul class="breadcrumbs-container">
<li><a href="index.html">PHP Manual</a></li>
<li><a href="mongo.types.html">Types</a></li>
<li>The MongoDate class</li>
</ul>
</div>
<div id="layout">
<div id="layout-content"><div id="class.mongodate" class="reference">
<h1 class="title">The MongoDate class</h1>
<div class="partintro"><p class="verinfo">(PECL mongo >=0.8.1)</p>
<div class="warning"><strong class="warning">Warning</strong>
<p class="para">This extension that defines this class
is deprecated. Instead, the <a href="" class="link">MongoDB</a> extension should be used.
Alternatives to this class include:</p>
<ul class="simplelist">
<li class="member"><strong class="classname">MongoDB\BSON\UTCDateTime</strong></li>
</ul>
</div>
<div class="section" id="mongodate.intro">
<h2 class="title">Introduction</h2>
<p class="para">
Represent date objects for the database. This class should be used to save
dates to the database and to query for dates. For example:
</p>
<div class="example" id="example-172">
<p><strong>Example #1 Storing dates with <strong class="classname">MongoDate</strong></strong></p>
<div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// save a date to the database<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-></span><span style="color: #0000BB">save</span><span style="color: #007700">(array(</span><span style="color: #DD0000">"ts" </span><span style="color: #007700">=> new </span><span style="color: #0000BB">MongoDate</span><span style="color: #007700">()));<br /><br /></span><span style="color: #0000BB">$start </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoDate</span><span style="color: #007700">(</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"2010-01-15 00:00:00"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$end </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoDate</span><span style="color: #007700">(</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"2010-01-30 00:00:00"</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// find dates between 1/15/2010 and 1/30/2010<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-></span><span style="color: #0000BB">find</span><span style="color: #007700">(array(</span><span style="color: #DD0000">"ts" </span><span style="color: #007700">=> array(</span><span style="color: #DD0000">'$gt' </span><span style="color: #007700">=> </span><span style="color: #0000BB">$start</span><span style="color: #007700">, </span><span style="color: #DD0000">'$lte' </span><span style="color: #007700">=> </span><span style="color: #0000BB">$end</span><span style="color: #007700">)));<br /><br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div>
<p class="para">
MongoDB stores dates as milliseconds past the epoch. This means that dates
<em class="emphasis">do not</em> contain timezone information. Timezones must be
stored in a separate field if needed. Second, this means that any precision
beyond milliseconds will be lost when the document is sent to/from the
database.
</p>
</div>
<div class="section" id="mongodate.synopsis">
<h2 class="title">Class synopsis</h2>
<div class="classsynopsis">
<div class="ooclass"></div>
<div class="classsynopsisinfo">
<span class="ooclass">
<strong class="classname">MongoDate</strong>
</span>
{</div>
<div class="classsynopsisinfo classsynopsisinfo_comment">/* Fields */</div>
<div class="fieldsynopsis">
<span class="modifier">public</span>
<span class="type">int</span>
<var class="varname">$<var class="varname">sec</var></var>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
<span class="type">int</span>
<var class="varname">$<var class="varname">usec</var></var>;</div>
<div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div>
<div class="methodsynopsis dc-description">
<span class="modifier">public</span> <span class="methodname"><a href="mongodate.construct.html" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$sec</code><span class="initializer"> = time()</span></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$usec</code><span class="initializer"> = 0</span></span>)</div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="mongodate.todatetime.html" class="methodname">toDateTime</a></span>(): <span class="type"><span class="type DateTime">DateTime</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="mongodate.tostring.html" class="methodname">__toString</a></span>(): <span class="type">string</span></div>
}</div>
</div>
</div>
<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="mongodate.construct.html">MongoDate::__construct</a> — Creates a new date</li><li><a href="mongodate.todatetime.html">MongoDate::toDateTime</a> — Returns a DateTime object representing this date</li><li><a href="mongodate.tostring.html">MongoDate::__toString</a> — Returns a string representation of this date</li></ul>
</div>
</div></div></body></html>