当前位置: 首页>>代码示例>>Python>>正文


Python DateTime.strptime方法代码示例

本文整理汇总了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
开发者ID:BackupTheBerlios,项目名称:skunkweb-svn,代码行数:24,代码来源:postconn.py

示例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()
开发者ID:KayneWest,项目名称:iem,代码行数:46,代码来源:rerun_fromfile.py

示例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")
开发者ID:wvl,项目名称:avidus,代码行数:8,代码来源:ds.py


注:本文中的DateTime.strptime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。