On Fri, Sep 19, 2014 at 10:50 PM, Cameron Simpson <[email protected]> wrote:
> 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]> You should read the last posts before posting. (: The problem was already solved, and as I said, it was already an int, not a str as I wrongly said on the title!
_______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
