PHP » PYTHON |
login |
register |
about
|
PYTHON strtotime
is this article helpful?
|
Python replacement for PHP's strtotime
[
edit
| history
]
Use timelib http://pypi.python.org/pypi/timelib/
>>> import timelib >>> timelib.strtodatetime('Sun Sep 19 12:50:34 +0000 2010') datetime.datetime(2010, 9, 19, 12, 50, 34) strtotime(PHP 4, PHP 5) strtotime — Parse about any English textual datetime description into a Unix timestamp Description
int strtotime
( string $time
[, int $now
] )
The function expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now , or the current time if now is not supplied. This function will use the TZ environment variable (if available) to calculate the timestamp. Since PHP 5.1.0 there are easier ways to define the timezone that is used across all date/time functions. That process is explained in the date_default_timezone_get() function page.
Parameters
Return ValuesReturns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure. Errors/ExceptionsEvery call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT message if using the system settings or the TZ environment variable. See also date_default_timezone_set() Changelog
Examples
Example #1 A strtotime() example
<?php
Example #2 Checking for failure
<?php
NotesWarning
In PHP 5 up to 5.0.2, "now" and other relative times are wrongly computed from today's midnight. It differs from other versions where it is correctly computed from current time. Warning
In PHP versions prior to 4.4.0, "next" is incorrectly computed as +2. A typical solution to this is to use "+1".
|
more
Recently updated
more
Most requested
|