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

Facebook Login
Site Registration

Calculating time differences given daylight savings time using Python

+5 votes
100 views

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?

posted Apr 3, 2014 by Jai Prakash

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

Similar Questions
+3 votes

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

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

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

+1 vote

I am able to see the absolute (exact) time on Win-XP of a file when it was last modified in hours, minutes, and seconds ("Today, May 11, 2014, 6:06:09 AM") by displaying the file properties.

On Windows 7, it displays the time as relative and a rough estimate ("Today, May 11, 2014, 2 hours ago"). How do I change it so it displays absolute time like Windows XP.

+1 vote

This function limits the"execution time" for a script. Is this CPU time or elapsed (wall-clock) time?

I'm asking because I'm running Win7 in a VirtualBox VM under OS X Mavericks. I've got an app that runs a number of scripts, using PHP 5.5.9. All runs correctly, but quite slowly, and a one script reports taking 20 secs or so of elapsed time when I might have expected 2 or 3 at most (as the same script running under OS X does).

I know that there is a note in the online doc for this function that says that under windows, extra time such as database calls is included. Would that include SQLite calls which wouldn't be included for the OS X version?

I've got a windows user whose scripts are actually running out of time, so I may have to add a php_value to the apache config to crank up the time limit.

+1 vote

For a long time I have been doing:

/etc/locale.conf change: LANG="en_US.UTF-8"
LANG="en_GB.UTF-8"

To make Thunderbird list messages with 24 hour time. Can someone suggest a better way to accomplish this?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...