@@ -138,3 +138,118 @@ you can create a ``Pendulum`` instance via the ``instance()`` function.
138138 p = pendulum.instance(dt)
139139 print (p.to_datetime_string())
140140 ' 2008-01-01 00:00:00'
141+
142+ Parsing
143+ -------
144+
145+ You can also instantiate ``Pendulum `` instances by passing a string to the ``parse() `` method.
146+
147+ .. code-block :: python
148+
149+ import pendulum
150+
151+ dt = pendulum.parse(' 1975-05-21 22:00:00' )
152+ print (dt)
153+ ' 1975-05-21T22:00:00+00:00
154+
155+ The library natively supports the RFC 3339 format, most ISO 8601 formats and some other common formats. If you pass a non-standard or more complicated
156+ string, the library will fallback on the `dateutil <https://dateutil.readthedocs.io >`_ parser.
157+
158+ RFC 3339
159+ ~~~~~~~~
160+
161+ +-----------------------------------+-------------------------------------------+
162+ | String |Output |
163+ +===================================+===========================================+
164+ | 1996-12-19T16:39:57-08:00 |1996-12-19T16:39:57-08:00 |
165+ +-----------------------------------+-------------------------------------------+
166+ | 1990-12-31T23:59:59Z |1990-12-31T23:59:59+00:00 |
167+ +-----------------------------------+-------------------------------------------+
168+
169+ ISO 8601
170+ ~~~~~~~~
171+
172+ Datetime
173+ ++++++++
174+
175+ +-----------------------------------+-------------------------------------------+
176+ | String |Output |
177+ +===================================+===========================================+
178+ | 20161001T143028+0530 |2016-10-01T14:30:28+05:30 |
179+ +-----------------------------------+-------------------------------------------+
180+ | 20161001T14 |2016-10-01T14:00:00+00:00 |
181+ +-----------------------------------+-------------------------------------------+
182+
183+ Date
184+ ++++
185+
186+ +-----------------------------------+-------------------------------------------+
187+ | String |Output |
188+ +===================================+===========================================+
189+ | 2012 |2012-01-01T00:00:00+00:00 |
190+ +-----------------------------------+-------------------------------------------+
191+ | 2012-05-03 |2012-05-03T00:00:00+00:00 |
192+ +-----------------------------------+-------------------------------------------+
193+ | 20120503 |2012-05-03T00:00:00+00:00 |
194+ +-----------------------------------+-------------------------------------------+
195+ | 2012-05 |2016-10-01T14:00:00+00:00 |
196+ +-----------------------------------+-------------------------------------------+
197+
198+ Ordinal day
199+ +++++++++++
200+
201+ +-----------------------------------+-------------------------------------------+
202+ | String |Output |
203+ +===================================+===========================================+
204+ | 2012-007 |2012-01-07T00:00:00+00:00 |
205+ +-----------------------------------+-------------------------------------------+
206+ | 2012007 |2012-01-07T00:00:00+00:00 |
207+ +-----------------------------------+-------------------------------------------+
208+
209+ Week number
210+ +++++++++++
211+
212+ +-----------------------------------+-------------------------------------------+
213+ | String |Output |
214+ +===================================+===========================================+
215+ | 2012-W05 |2012-01-30T00:00:00+00:00 |
216+ +-----------------------------------+-------------------------------------------+
217+ | 2012W05 |2012-01-30T00:00:00+00:00 |
218+ +-----------------------------------+-------------------------------------------+
219+ | 2012-W05-5 |2012-02-03T00:00:00+00:00 |
220+ +-----------------------------------+-------------------------------------------+
221+ | 2012W055 |2012-02-03T00:00:00+00:00 |
222+ +-----------------------------------+-------------------------------------------+
223+
224+ Time
225+ ++++
226+
227+ When passing only time information the date will default to today.
228+
229+ +-----------------------------------+-------------------------------------------+
230+ | String |Output |
231+ +===================================+===========================================+
232+ | 00:00 |2016-12-17T00:00:00+00:00 |
233+ +-----------------------------------+-------------------------------------------+
234+ | 12:04:23 |2016-12-17T12:04:23+00:00 |
235+ +-----------------------------------+-------------------------------------------+
236+ | 120423 |2016-12-17T12:04:23+00:00 |
237+ +-----------------------------------+-------------------------------------------+
238+ | 12:04:23.45 |2016-12-17T12:04:23.450000+00:00 |
239+ +-----------------------------------+-------------------------------------------+
240+
241+
242+ .. note ::
243+
244+ You can pass the ``strict `` keyword argument to ``parse() `` to get the exact time
245+ that the string represents:
246+
247+ .. code-block :: python
248+
249+ import pendulum
250+
251+ pendulum.parse(' 2012-05-03' , strict = True )
252+ # <Date [2012-05-03]>
253+
254+ pendulum.parse(' 12:04:23' , strict = True )
255+ # <Time [12:04:23]>
0 commit comments