PHP » PYTHON |
login |
register |
about
|
import time time.strftime ('%m/%d/%Y %H:%M') time.strftime ('%m/%d/%Y %H:%M', time.time()) Below is another more verbose option. import datetime def date(unixtime, format = '%m/%d/%Y %H:%M'): d = datetime.datetime.fromtimestamp(unixtime) return d.strftime(format) Examples: >>> import time >>> date(time.time()) '03/20/2012 18:10' To look at all the formats, please refer to: http://docs.python.org/library/time.html#time.strftime date(PHP 4, PHP 5) date — Format a local time/date Description
string date
( string $format
[, int $timestamp
] )
Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time(). Parameters
Return ValuesReturns a formatted date string. If a non-numeric value is used for timestamp , FALSE is returned and an E_WARNING level error is emitted. 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 date() examples
<?php
You can prevent a recognized character in the format string from being expanded by escaping it with a preceding backslash. If the character with a backslash is already a special sequence, you may need to also escape the backslash. Example #2 Escaping characters in date()
<?php
It is possible to use date() and mktime() together to find dates in the future or the past. Example #3 date() and mktime() example
<?php
Some examples of date() formatting. Note that you should escape any other characters, as any which currently have a special meaning will produce undesirable results, and other characters may be assigned meaning in future PHP versions. When escaping, be sure to use single quotes to prevent characters like \n from becoming newlines. Example #4 date() Formatting
<?php
To format dates in other languages, you should use the setlocale() and strftime() functions instead of date(). Notes
Tip
Timestamp of the start of the request is available in $_SERVER['REQUEST_TIME'] since PHP 5.1. See Also
|
more
Recently updated
more
Most requested
more
Last requests
|