On 19Sep2014 20:46, Juan Christian <[email protected]> wrote:
On Fri, Sep 19, 2014 at 8:22 PM, Danny Yoo <[email protected]> wrote:
   Anyway, can you use ctime()?  It looks like that might be almost right:
       >>> t = 1411167038
       >>> datetime.datetime.utcfromtimestamp(t).ctime()
       'Fri Sep 19 22:50:38 2014'

The thing is that I get the timestamp as string and I need to print it using
something like this: print("Random text here: {}".format(my_date))

    # here's your timestamp as a string, however obtained
    t = <timestamp as string>

    # just an int, convert it to an int
    seconds_since_epoch = int(t)

    # get a <datetime> from the timestamp
    dt = datetime.datetime.utcfromtimestamp(t)

    # write the <datetime> out in desired format as a string
    my_date = dt.strftime("%a, %d %b %Y %H:%M:%S")

    # use the formatted string
    print("Random text here: {}".format(my_date))

Seriously, keep that steps all broken out separately like the above. Easier to read, easier to debug, easier to move relevant parts off into utility functions later when you need to do this from several places in your code.

Cheers,
Cameron Simpson <[email protected]>

If this experiment we're doing works, then I will follow up and push it as
hard as possible. And if it doesn't work, I will write a science-fiction
novel where it does work. It's a win-win situation.
- John Cramer on his experiment for possible cuasality violation
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to