top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to properly get the microseconds from the timestamps using python?

+3 votes

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

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

posted Apr 22, 2014 by Amit Mishra

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

1 Answer

+1 vote

I believe, in these cases, you can just test, whether there is a non-integer part in the timestamp in seconds, which will be stored as microseconds accordingly.

0.2 s is stored (and shown in repr(...)) as 200000 microseconds.

There are some peculiarities in handling date and time calculations reliably as well as in the floating point math, but they don't seem to be involved here.

answer Apr 22, 2014 by Parveen
Similar Questions
+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

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

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

+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.

0 votes

I have a list of a list of integers. The lists are long so i cant really show an actual example of on of the lists, but I know that they contain only the integers 1,2,3,4.

so for example. s2 = [[1,2,2,3,2,1,4,4],[2,4,3,2,3,1]]

I am calculating the product, sum, max, min.... of each list in s2 but I get negative or 0 for the product for a lot of the lists. (I am doing this in ipython)

for x in s2: Â  Â  print(len = , len(x), sum = , sum(x), prod = , prod(x), max = , max(x), min = , min(x))
 (len = , 100, sum = , 247, prod = , 0, max = , 4, min = , 1) (len = , 100, sum = , 230, prod = , -4611686018427387904, max = , 4, min = , 1) (len = , 100, sum = , 261, prod = , 0, max = , 4, min = , 1)
 (prod =, 0, max =, 4, min =, 1) (prod =, 1729382256910270464, max =, 4, min =, 1) (prod =, 0, max =, 4, min =, 1)

Whats going on?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.