GBSTimeStamp.py

Go to the documentation of this file.
00001 import datetime
00002 import time
00003 
00004 
00005 def GBSTimeStamp():
00006     """Standard timestamp corresponding to the current time."""
00007     return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S ')
00008 
00009 def TimeStampToUnixTime(time_stamp):
00010     """Convert time stamp string (with optional time component) to Unix time."""
00011     try: return time.mktime(time.strptime(time_stamp,"%Y-%m-%d %H:%M:%S"))
00012     except:
00013         try: return time.mktime(time.strptime(time_stamp,"%Y-%m-%d"))
00014         except:
00015             print "TimeStampToUnixTime: invalid time stamp:" + str(time_stamp)
00016             return None
00017 
00018 def UnixTimeToTimeStamp(unix_time):
00019     """Convert Unix time to time stamp string."""
00020     try: return datetime.datetime.fromtimestamp(unix_time).strftime("%Y-%m-%d %H:%M:%S")
00021     except:
00022         print "UnixTimeToTimeStamp: invalid Unix time " + str(unix_time)
00023         return None

Generated on Fri Mar 5 09:25:41 2010 for gbs by  doxygen 1.4.7