Re: date formatting

Discussion in 'Python' started by Jeremy Dillworth, Sep 12, 2003.

  1. This works, with Python 2.3:

    from datetime import datetime
    datetime.fromtimestamp(os.stat('thefile').st_mtime).strftime('%y%d%m')

    It leaves out the call to localtime, but now you're constructing a
    datetime object, so it's really not more direct. Some may find it
    more readable, or at least I think it is, er... well slightly :)

    On Linux os.stat() returns an object of type posix.stat_result,
    I wonder if this type could be enhanced so that one could do this:

    os.stat('thefile').mdatetime.strftime('%y%d%m')

    (mdatetime returning a datetime object)

    Naturally we'd probably want os.stat('thefile').cdatetime and so
    on too...


    --- WmGill <> wrote:
    > I want to write a script that Among other things) renames a file based on
    > it's timestamp.
    > I can get the date info using
    > "strftime('%y%m%d',localtime(os.stat('thefile')[ST_MTIME])", but this seems
    > like a long way around the block. Is there a more direct way?
    >
    > Bill
    >
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    Jeremy Dillworth, Sep 12, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    564
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,179
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    491
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    689
    Richard Heathfield
    Nov 8, 2003
  5. Matt
    Replies:
    11
    Views:
    382
    Aaron Bertrand [MVP]
    Nov 8, 2003
Loading...

Share This Page