How to get formatted date time in Python the same way as in PHP
date('M d Y', $timestamp);
?
相关问题
- Views base64 encoded blob in HTML with PHP
- how to define constructor for Python's new Nam
- Laravel Option Select - Default Issue
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
Way back in 2003, Simon Willison wrote DateFormat, a little date format translation class which enables php-style date format strings in Python:
DateFormat is available here: http://simonwillison.net/2003/oct/7/dateinpython/
The date, datetime, and time objects all support a strftime(format) method, to create a string representing the time under the control of an explicit format string.
Here is a list of the format codes with their directive and meaning.
This is what we can do with the datetime and time modules in Python
That will print out something like this:
You can use a suitable
strftime
function. Here is an example usingdatetime
objects.