本文整理汇总了Python中DateTime.strptime方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.strptime方法的具体用法?Python DateTime.strptime怎么用?Python DateTime.strptime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime
的用法示例。
在下文中一共展示了DateTime.strptime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _dateConvertFromDB
# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import strptime [as 别名]
def _dateConvertFromDB(d):
if d==None:
return None
try: return DateTime.strptime(d, '%Y-%m-%d') #just Y/M/D
except: pass
try: return DateTime.strptime(d, '%H:%M:%S') #just hh:mm:ss
except: pass
dashind = string.rindex(d, '-')
tz = d[dashind:]
d = d[:dashind]
try: return DateTime.strptime(d, '%H:%M:%S'), tz # timetz
except: pass
# NO -- it was already stripped off, above! -- js Thu Aug 9 11:51:23 2001
#strip off offset from gmt
#d = d[:string.rindex(d, '-')]
try:
return DateTime.strptime(d, '%Y-%m-%d %H:%M:%S') # full date
except:
#print "date passed to convert function: |%s|" % d
raise
示例2: process
# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import strptime [as 别名]
def process(file):
f = open(file, 'r').readlines()
i = int( file[:-4] )
# Loop over these lines
for line in f:
tokens = re.split(",",line)
if (len(tokens) > 4): # Simple test to make sure line is long
# For now, we are ignoring the Max/Min lines
myDate = tokens[1]
myTime = tokens[0]
thisTime = DateTime.strptime(myDate +" "+ myTime, "%m/%d/%y %H:%M")
myMinute = int(myTime[3:5])
if (myMinute == 0 or myMinute == 20 or myMinute == 40):
gmtTime = thisTime + DateTime.RelativeDateTime(hours=+6)
filePre = gmtTime.strftime("%Y%m%d")
gempakTime = gmtTime.strftime("%y%m%d/%H%M")
fref = open('/tmp/'+filePre+'.fil', 'a')
try:
fref.write(" "+ snetConv[i] +" "+ gempakTime +" ")
tempF = int( (tokens[6])[:-1] )
RH = int( (tokens[7])[:3] )
dirTxt = tokens[2]
mph = (tokens[3])[:-3]
knots = round(float(mph) / 1.1507, 2)
alti = tokens[8]
p24i = (tokens[9])[:-2]
srad = int( (tokens[4])[:-1] ) * 10
drct = txt2drct[dirTxt]
dwpf = dewPoint(float(tempF), float(RH) )
fref.write( str(tempF) +" "+ str(RH) +" "+str(dwpf) +" " \
+ str(drct)+" "+ str(knots) +" "+ str(p24i) +" "+ str(srad)+"\n")
except KeyError:
hi = "hello"
fref.close()
示例3: ds_toDate
# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import strptime [as 别名]
def ds_toDate(datestring):
"convert a string to a DateTime object"
# should catch exceptions here....
#return(DateTimeFrom(datestring))
return DateTime.strptime(datestring, "%d-%b-%y")