collect more date formatting and parsing utilities in one central place

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3731 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2010-02-15 11:33:06 +00:00
parent 36b964fc8e
commit 31a2195958

View file

@ -25,13 +25,29 @@ $Id$
import time
def getTimeStamp():
return int(time.time())
def timeStamp2ISO(ts, useGM=False, format='%Y-%m-%d %H:%M'):
return formatTimeStamp(ts, useGM, format)
def formatTimeStamp(ts, useGM=False, format='%Y-%m-%d %H:%M'):
if ts is None:
ts = getTimeStamp()
fct = useGM and time.gmtime or time.localtime
return time.strftime(format, fct(ts))
#return time.strftime('%Y-%m-%d %H:%M', time.gmtime(ts))
#return time.strftime('%Y-%m-%d %H:%M', time.localtime(ts))
def getTimeStamp():
return int(time.time())
def str2timeStamp(s):
try:
t = time.strptime(s, '%Y-%m-%d %H:%M:%S')
except ValueError:
try:
t = time.strptime(s, '%Y-%m-%d %H:%M')
except ValueError:
t = time.strptime(s, '%Y-%m-%d')
return int(time.mktime(t))