On Thu, Apr 5, 2012 at 1:52 PM, Jabba Laci <jabba.l...@gmail.com> wrote:
> Hi,
>
> Unix's date command produces this output (example):
>
> Thu Apr  5 22:49:42 CEST 2012
>
> I would like to produce the same output with Python, without calling
> "date" externally. Before doing it I'd like to ask the list if anyone
> has an existing solution for this.

From POSIX (http://pubs.opengroup.org/onlinepubs/009695399/utilities/date.html
):
    When no formatting operand is specified, the output in the POSIX
locale shall be equivalent to specifying:
    date "+%a %b %e %H:%M:%S %Z %Y"

Therefore:
    from time import strftime
    print strftime("%a %b %e %H:%M:%S %Z %Y")

But note that `date` is locale-sensitive; imitating that would be a
bit more complicated.

Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to