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


Python DateTime类代码示例

本文整理汇总了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
开发者ID:xeecos,项目名称:astrobin,代码行数:33,代码来源:moon.py

示例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)
开发者ID:rfleschenberg,项目名称:egenix-mx-base-python-2x3,代码行数:29,代码来源:ARPA.py

示例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)
开发者ID:rfleschenberg,项目名称:egenix-mx-base-python-2x3,代码行数:34,代码来源:ARPA.py

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

示例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
开发者ID:akrherz,项目名称:pals,代码行数:8,代码来源:editHourly.py

示例6: add_entry

def add_entry(ticks, comments, analysis, caseNum):
	comments = regsub.gsub("'","&#180;", comments)
	analysis = regsub.gsub("'","&#180;", 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'
开发者ID:akrherz,项目名称:pals,代码行数:10,代码来源:addHourly.py

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

示例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)
开发者ID:xeecos,项目名称:astrobin,代码行数:11,代码来源:moon.py

示例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)
开发者ID:akrherz,项目名称:pals,代码行数:12,代码来源:del.py

示例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        
开发者ID:socialplanning,项目名称:opencore,代码行数:12,代码来源:stats.py

示例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
开发者ID:Conectivo,项目名称:opencore,代码行数:12,代码来源:email_invites.py

示例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
开发者ID:BackupTheBerlios,项目名称:skunkweb-svn,代码行数:22,代码来源:postconn.py

示例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>'
开发者ID:akrherz,项目名称:pals,代码行数:51,代码来源:edit.py

示例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)
开发者ID:alpha-beta-soup,项目名称:national-crash-statistics,代码行数:14,代码来源:moon.py

示例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
开发者ID:akrherz,项目名称:pals,代码行数:16,代码来源:editHourly.py


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