top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Print seconds from the epoch including the millisecond

+3 votes
444 views

I am using 2.7. I need to print the time in seconds from the epoch with millisecond precision. I have tried many things but have failed.

 from time import time, strftime
 from datetime import datetime, time

 # write date, time, then seconds from epoch
 self.logfile.write('%st'%(strftime("%Y-%m-%d",)))
 self.logfile.write('%st'%(now.strftime("%H:%M:%S",)))
 self.logfile.write('%st'%(now.time()))

What am i doing wrong? What should I be doing here?

posted Dec 26, 2013 by Deepak Dasgupta

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

In [1]: import time

In [2]: time.time()
Out[2]: **********.1567955

answer Dec 26, 2013 by Seema Siddique
Similar Questions
0 votes

Is print thread safe? That is, if I have two threads that each call print, say:

print "spam spam spam" # thread 1
print "eggs eggs eggs" # thread 2

I don't care which line prints first, but I do care if the two lines are mixed in together, something like this:

spam spaeggs eggs m seggspams

Does print perform its own locking to prevent this?

+3 votes

import datetime
datetime.datetime.fromtimestamp(**********)
datetime.datetime(2004, 8, 17, 17, 0)

Is there a way to know if the timestamp has a microseconds?

+5 votes

I am running Python 2.7 and would like to be able to calculate to the second the time difference between now and some future date/time in the same timezone while taking into account daylight savings time. I do not have pytz. Any ideas how to do it?

If it requires having pytz, how would I do it with pytz?

+3 votes

Can anyone provide the number of seconds from 1st Jan 1900 to 1st Jan 1970 (EPOCH)?

+4 votes

Is there a command i can issue to get the exact system time that the remote Tomcat server is using? And then is there a command or some way (with applicable admin rights) to set the remote time?

The idea is the sync'ing of the different PC's I am hoping to use, if there is some other way used I am grateful to hear it. I am setting up a distributed system that's running in Linux.

...