本文整理汇总了Python中DateTime类的典型用法代码示例。如果您正苦于以下问题:Python DateTime类的具体用法?Python DateTime怎么用?Python DateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: phase_hunt
def phase_hunt(sdate=DateTime.now()):
"""Find time of phases of the moon which surround the current date.
Five phases are found, starting and ending with the new moons
which bound the current lunation.
"""
if not hasattr(sdate,'jdn'):
sdate = DateTime.DateTimeFromJDN(sdate)
adate = sdate + DateTime.RelativeDateTime(days=-45)
k1 = floor((adate.year + ((adate.month - 1) * (1.0/12.0)) - 1900) * 12.3685)
nt1 = meanphase(adate, k1)
adate = nt1
sdate = sdate.jdn
while 1:
adate = adate + c.synodic_month
k2 = k1 + 1
nt2 = meanphase(adate,k2)
if nt1 <= sdate < nt2:
break
nt1 = nt2
k1 = k2
phases = list(map(truephase,
[k1, k1, k1, k1, k2],
[0/4.0, 1/4.0, 2/4.0, 3/4.0, 0/4.0]))
return phases
示例2: ParseDate
def ParseDate(arpastring,parse_arpadate=arpadateRE.match):
""" ParseDate(arpastring)
Returns a DateTime instance reflecting the given ARPA
date. Only the date part is parsed, any time part will be
ignored. The instance's time is set to 0:00:00.
"""
s = arpastring.strip()
date = parse_arpadate(s)
if not date:
raise ValueError,'wrong format'
litday,day,litmonth,month,year = date.groups()
if len(year) == 2:
year = DateTime.add_century(int(year))
else:
year = int(year)
if litmonth:
litmonth = litmonth.lower()
try:
month = litmonthtable[litmonth]
except KeyError:
raise ValueError,'wrong month format'
else:
month = int(month)
day = int(day)
# litday and timezone are ignored
return DateTime.DateTime(year,month,day)
示例3: ParseDateTime
def ParseDateTime(arpastring,parse_arpadatetime=arpadatetimeRE.match):
""" ParseDateTime(arpastring)
Returns a DateTime instance reflecting the given ARPA date
assuming it is local time (timezones are silently ignored).
"""
s = arpastring.strip()
date = parse_arpadatetime(s)
if not date:
raise ValueError,'wrong format or unknown time zone'
litday,day,litmonth,month,year,hour,minute,second,zone = date.groups()
if len(year) == 2:
year = DateTime.add_century(int(year))
else:
year = int(year)
if litmonth:
litmonth = litmonth.lower()
try:
month = litmonthtable[litmonth]
except KeyError:
raise ValueError,'wrong month format'
else:
month = int(month)
day = int(day)
hour = int(hour)
minute = int(minute)
if second is None:
second = 0.0
else:
second = float(second)
# litday and timezone are ignored
return DateTime.DateTime(year,month,day,hour,minute,second)
示例4: _test
def _test():
import ISO,ARPA
year = DateTime.now().year
print 'Easter Sunday for the next few years'
for i in range(10):
easter = EasterSunday(year+i)
print 'ISO:',ISO.str(easter),' ARPA:', ARPA.str(easter)
示例5: get_entry
def get_entry(caseNum, ticks):
thisDate = DateTime.gmtime(ticks)
findDate = DateTime.ISO.strGMT(thisDate)
entries = mydb.query("SELECT comments, analysis from annotations where ( validtime = '"+findDate+"' and casenum = '"+caseNum+"' )")
entries = entries.getresult()
return entries
示例6: add_entry
def add_entry(ticks, comments, analysis, caseNum):
comments = regsub.gsub("'","´", comments)
analysis = regsub.gsub("'","´", analysis)
thisDate = DateTime.gmtime(ticks)
findDate = DateTime.ISO.strGMT(thisDate)
delete = mydb.query("delete from annotations WHERE validtime = '"+findDate+"' and casenum = '"+caseNum+"' ")
insert = mydb.query("insert into annotations (validtime, comments, analysis, casenum) values('"+findDate+"','"+comments+"','"+analysis+"','"+caseNum+"')")
print 'DONE'
示例7: getData
def getData(symbol, startdate=0):
symbol = string.lower(symbol)
adate = []
open_tmp = []
high_tmp = []
low_tmp = []
close_tmp = []
vol_tmp = []
have_vol = 0
if startdate == 0:
startdate = DateTime.DateTime(1900,1,1)
if db[symbol].has_key('StartDate'):
if startdate < db[symbol]['StartDate']:
startdate = db[symbol]['StartDate']
else:
raise 'DB not set properly - no startdate'
dir = os.path.join(data_dir, symbol)
nowyear = DateTime.now().year
for i in range(nowyear - startdate.year + 1):
filename = os.path.join(dir, `nowyear-i`, 'daily.dat')
infile = open(filename, 'r')
filebuf = infile.read()
infile.close
l = string.split(filebuf,'\n')
i=0
while i<(len(l)):
nums = string.split(l[i], ',')
if (len(nums) >= 5):
date = ds_toDate(nums[0])
if (date >= startdate) or startdate==0:
adate.append(date)
open_tmp.append(float(nums[1]))
high_tmp.append(float(nums[2]))
low_tmp.append(float(nums[3]))
close_tmp.append(float(nums[4]))
else:
pass
if (len(nums) == 6):
have_vol = 1
vol_tmp.append(float(nums[5]))
else:
have_vol = 0
i = i + 1
return adate, Numeric.array(open_tmp), Numeric.array(high_tmp), \
Numeric.array(low_tmp), Numeric.array(close_tmp), \
Numeric.array(vol_tmp)
示例8: __init__
def __init__(self, date=DateTime.now()):
"""MoonPhase constructor."""
if isinstance(date, DateTime.DateTimeType):
self.date = date
else:
self.date = DateTime.DateTimeFrom(date)
self.__dict__.update(phase(self.date))
self.phase_text = phase_string(self.phase)
示例9: Main
def Main():
form = cgi.FormContent()
zticks = str(form["zticks"][0])
caseNum = str(form["caseNum"][0])
nowDate = DateTime.gmtime(zticks)
strTicks = DateTime.ISO.strGMT(nowDate)
delete = mydb.query("DELETE from specquestions WHERE validTime = '"+strTicks+"' ")
style.jump_page('index.py?caseNum='+caseNum)
示例10: __init__
def __init__(self, context, request):
self.context = context
self.request = request
self.catalog = getToolByName(self.context, 'portal_catalog')
self.membrane_tool = getToolByName(self.context, 'membrane_tool')
self.expiry_days = 30
r_date = getattr(self.request, 'report_date', None)
if r_date:
self.report_date = DateTime.DateTime(r_date)
else:
self.report_date = DateTime.now()
self.expiry_date = self.report_date-self.expiry_days
示例11: addInvitation
def addInvitation(self, address, proj_id):
now = DateTime.now()
invitekeymap = self.getInvitesByEmailAddress(address)
if proj_id not in invitekeymap:
invitekeymap[proj_id] = now
self._by_address[address] = invitekeymap
by_project = self.getInvitesByProject(proj_id)
if address not in by_project:
by_project[address] = now
self._by_project[proj_id] = by_project
return invitekeymap.key
示例12: _dateConvertFromDB
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
示例13: Main
def Main():
style.header("Edit Questions", "white")
form = cgi.FormContent()
zticks = form["zticks"][0]
caseNum = form["caseNum"][0]
zticks = int( float(zticks) )
nowDate = DateTime.gmtime(zticks)
nice_date = nowDate.strftime("%x %H Z")
strTicks = DateTime.ISO.strGMT(nowDate)
add_entry( strTicks )
print '<H2 align="CENTER">Edit Question for '+nice_date+':</H2>'
print '<HR>'
print '<a href="del.py?caseNum='+caseNum+'&zticks='+str(zticks)+'">Delete this question from DB</a>'
entry = mydb.query("SELECT * from "+table_str+" WHERE validTime = '"+strTicks+"' ").dictresult()
question = entry[0]["question"]
type = entry[0]["type"]
optiona = entry[0]["optiona"]
optionb = entry[0]["optionb"]
optionc = entry[0]["optionc"]
optiond = entry[0]["optiond"]
optione = entry[0]["optione"]
optionf = entry[0]["optionf"]
answer = entry[0]["answer"]
cor_comments = entry[0]["correct"]
wro_comments = entry[0]["wrong"]
print '<form method="POST" action="change.py">'
print '<input type="hidden" name="validTime" value="'+strTicks+'">'
print '<input type="hidden" name="caseNum" value="'+caseNum+'">'
mk_question(question)
mk_type(type)
mk_optiona(optiona)
mk_optionb(optionb)
mk_optionc(optionc)
mk_optiond(optiond)
mk_optione(optione)
mk_optionf(optionf)
mk_answer(answer)
mk_cor_comments(cor_comments)
mk_wro_comments(wro_comments)
print '<input type="SUBMIT" value="Make Changes">'
print '</form></body></html>'
示例14: __init__
def __init__(self, date=DateTime.now()):
"""MoonPhase constructor.
Give me a date, as either a Julian Day Number or a DateTime
object."""
if not isinstance(date, DateTime.DateTimeType):
self.date = DateTime.DateTimeFromJDN(date)
else:
self.date = date
self.__dict__.update(phase(self.date))
self.phase_text = phase_string(self.phase)
示例15: get_entry
def get_entry(caseNum, ticks):
thisDate = DateTime.gmtime(ticks)
findDate = DateTime.ISO.strGMT(thisDate)
entries1 = mydb.query("SELECT comments, analysis from annotations where ( validtime = '"+findDate+"' and casenum = '"+caseNum+"' )")
entries2 = mydb1.query("SELECT comments, analysis from annotations where ( validtime = '"+findDate+"' and casenum = '"+caseNum+"' )")
entries3 = mydb1.query("SELECT comments, analysis from annotations_custom where ( validtime = '"+findDate+"' and casenum = '"+caseNum+"' and className = '"+className+"')")
entries1 = entries1.dictresult()
entries2 = entries2.dictresult()
entries3 = entries3.dictresult()
if len(entries3) > 0:
return entries3
if len(entries2) > 0:
return entries2
return entries3