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


Python DateTime.now方法代码示例

本文整理汇总了Python中DateTime.now方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.now方法的具体用法?Python DateTime.now怎么用?Python DateTime.now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTime的用法示例。


在下文中一共展示了DateTime.now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: phase_hunt

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
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,代码行数:35,代码来源:moon.py

示例2: _test

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
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,代码行数:10,代码来源:Feasts.py

示例3: getData

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
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,代码行数:57,代码来源:ds.py

示例4: __init__

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
    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,代码行数:13,代码来源:moon.py

示例5: __init__

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
 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,代码行数:14,代码来源:stats.py

示例6: addInvitation

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
    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,代码行数:14,代码来源:email_invites.py

示例7: __init__

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
    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,代码行数:16,代码来源:moon.py

示例8: downloadCart

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
 def downloadCart (self):
     if self.isEmpty ():
         self.context.plone_utils.addPortalMessage(self.msg['isEmpty'])   
     else :
         result = []
         for item in self.cart.items ():
             pc = self.context.portal_catalog (UID=item[0])
             if len(pc) != 0:
                 result.append (pc[0])
         FileCartZip (self.request, result)
         user = getSecurityManager().getUser().getId()
         comment = dict(
             user = user,
             date = DateTime.now(),
             comment = self.request.form['filecart_download_comment'],)
         filecartcommentsutility = getUtility(interfaces.IFileCartCommentsUtility)
         filecartcommentsutility.commentDownload(self.context, result, comment)
         self.context.plone_utils.addPortalMessage(self.msg['download'])
开发者ID:atreal,项目名称:atreal.filecart,代码行数:20,代码来源:filecart.py

示例9: addSymbol

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
def addSymbol(symbol):
    sybmol = string.lower(symbol)
    symbols.append(symbol)
    dir = os.path.join(data_dir, symbol)
    try:
        os.chdir(dir)
    except:
        os.makedirs(dir)

    startyear = db['startdate'].year
    for i in range(DateTime.now().year - startyear + 1):
        datepath = os.path.join(dir, `startyear+i`)
        try:
            os.chdir(datepath)
        except:
            os.makedirs(datepath)
    
    updateSymbol(symbol)
    db['symbols'] = symbols
开发者ID:wvl,项目名称:avidus,代码行数:21,代码来源:ds.py

示例10: loadSymbol

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
    def loadSymbol(self, symbol):
        if Avidus.ds.hasSymbol(symbol):
            import DateTime
            date = DateTime.now() - DateTime.RelativeDate(years=+5)
            self.mData.setData(Avidus.ds.getData(symbol, date), symbol)
        else:
            message = 'Invalid symbol'
            self.emit(PYSIGNAL("statusMessage"), (message,))
            QMessageBox.information(self, 't a c t',
               """Invalid Symbol""")
            return
        
        self.xsize = self.mX.UpdateData(self.mData,self.width())

        
        if self.splitter.width() != self.xsize:
            self.mChart.UpdateData(DataSet())
            for i in range(len(self.mIndCharts)):
                self.mIndCharts[i].UpdateData(DataSet())
            self.resizeContents(self.xsize, self.visibleHeight())
            self.splitter.resize(self.xsize, self.visibleHeight())
            
            # move to the far right
            self.center(4000,0,0,0)
            
        #print 'got a size of: ', self.width(), self.height()
        #print 'got a size of: ', self.mChart.width(), self.mChart.height()
        #print 'got a size of: ', self.splitter.width(), self.splitter.height()
        
        self.mChart.UpdateData(self.mData)
        for i in range(len(self.mIndCharts)):
            self.mIndCharts[i].UpdateData(self.mData)

        # move to the far right
        self.center(4000,0,0,0)
        
        message = symbol + ' loaded.'
        self.emit(PYSIGNAL("statusMessage"), (message,))

        self.ticker.insertItem(symbol,0)
开发者ID:wvl,项目名称:avidus,代码行数:42,代码来源:ChartWindow.py

示例11: ds_updateSymbolData

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
def ds_updateSymbolData(symbol, begin_date, start=0):
    symbol = string.lower(symbol)

    lastdate = DateTime.now()
    if begin_date > lastdate:
        return
    else:
        date = DateTime.DateTime(begin_date.year, 1, 1)
    print 'Getting data for ', symbol, ' from ', str(date)
    
    infile = di.getData(symbol, date, lastdate)
    throwawayline = infile.readline()
    indata = infile.readlines()

    index = 0
    got_start = 0
    
    startyear = date.year
    endyear = lastdate.year
    curdate = lastdate

    for i in range(endyear - startyear + 1):
        print 'Adding year: ', `endyear - i`
        
        datastring = ''
        while index < len(indata):
            line = indata[index]
            nums = string.split(line, ',')
            if len(nums) >= 5:
                d = ds_toDate(nums[0])
                if d.year < (endyear - i):
                    break
                else:
                    index = index+1
                    curdate = ds_toDate(nums[0])
                    datastring = datastring + line

        dir = os.path.join(data_dir, symbol)
        datfilename = os.path.join(dir, `curdate.year`, 'daily.dat')
        print 'Writing to: ', datfilename, len(datastring)
        datfile = open(datfilename, 'w')
        datfile.write(datastring)
        datfile.close()

        # We didn't get all the data we asked for.  Set the start
        # date and exit our loop
        if index >= len(indata):
            begin_date = curdate
            got_start = 1
            print 'Hit got start for ', symbol
            break

    if db.has_key(symbol):
        symbdata = db[symbol]
    else:
        symbdata = {}
        
    if start:
        symbdata['StartDate'] = begin_date

    if not symbdata.has_key('GotStart'):
        if got_start:
            symbdata['GotStart'] = 1
            
    symbdata['LastDate'] = lastdate
    db[symbol] = symbdata
开发者ID:wvl,项目名称:avidus,代码行数:68,代码来源:ds.py

示例12: phase

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
def phase(phase_date=DateTime.now()):
    """Calculate phase of moon as a fraction:

    The argument is the time for which the phase is requested,
    expressed in either a DateTime or by Julian Day Number.

    Returns a dictionary containing the terminator phase angle as a
    percentage of a full circle (i.e., 0 to 1), the illuminated
    fraction of the Moon's disc, the Moon's age in days and fraction,
    the distance of the Moon from the centre of the Earth, and the
    angular diameter subtended by the Moon as seen by an observer at
    the centre of the Earth."""

    # Calculation of the Sun's position

    # date within the epoch
    if hasattr(phase_date, "jdn"):
        day = phase_date.jdn - c.epoch
    else:
        day = phase_date - c.epoch

    # Mean anomaly of the Sun
    N = fixangle((360/365.2422) * day)
    # Convert from perigee coordinates to epoch 1980
    M = fixangle(N + c.ecliptic_longitude_epoch - c.ecliptic_longitude_perigee)

    # Solve Kepler's equation
    Ec = kepler(M, c.eccentricity)
    Ec = sqrt((1 + c.eccentricity) / (1 - c.eccentricity)) * tan(Ec/2.0)
    # True anomaly
    Ec = 2 * todeg(atan(Ec))
    # Suns's geometric ecliptic longuitude
    lambda_sun = fixangle(Ec + c.ecliptic_longitude_perigee)

    # Orbital distance factor
    F = ((1 + c.eccentricity * cos(torad(Ec))) / (1 - c.eccentricity**2))

    # Distance to Sun in km
    sun_dist = c.sun_smaxis / F
    sun_angular_diameter = F * c.sun_angular_size_smaxis

    ########
    #
    # Calculation of the Moon's position

    # Moon's mean longitude
    moon_longitude = fixangle(13.1763966 * day + c.moon_mean_longitude_epoch)

    # Moon's mean anomaly
    MM = fixangle(moon_longitude - 0.1114041 * day - c.moon_mean_perigee_epoch)

    # Moon's ascending node mean longitude
    # MN = fixangle(c.node_mean_longitude_epoch - 0.0529539 * day)

    evection = 1.2739 * sin(torad(2*(moon_longitude - lambda_sun) - MM))

    # Annual equation
    annual_eq = 0.1858 * sin(torad(M))

    # Correction term
    A3 = 0.37 * sin(torad(M))

    MmP = MM + evection - annual_eq - A3

    # Correction for the equation of the centre
    mEc = 6.2886 * sin(torad(MmP))

    # Another correction term
    A4 = 0.214 * sin(torad(2 * MmP))

    # Corrected longitude
    lP = moon_longitude + evection + mEc - annual_eq + A4

    # Variation
    variation = 0.6583 * sin(torad(2*(lP - lambda_sun)))

    # True longitude
    lPP = lP + variation

    #
    # Calculation of the Moon's inclination
    # unused for phase calculation.
    
    # Corrected longitude of the node
    # NP = MN - 0.16 * sin(torad(M))

    # Y inclination coordinate
    # y = sin(torad(lPP - NP)) * cos(torad(c.moon_inclination))

    # X inclination coordinate
    # x = cos(torad(lPP - NP))

    # Ecliptic longitude (unused?)
    # lambda_moon = todeg(atan2(y,x)) + NP

    # Ecliptic latitude (unused?)
    # BetaM = todeg(asin(sin(torad(lPP - NP)) * sin(torad(c.moon_inclination))))

    #######
    #
#.........这里部分代码省略.........
开发者ID:xeecos,项目名称:astrobin,代码行数:103,代码来源:moon.py

示例13: modification_made

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
def modification_made(obj, event):
    # get portal object and set the last_modified_header
    portal = getToolByName(obj, 'portal_url').getPortalObject()
    portal.last_modified_header = DateTime.now()
开发者ID:uwosh,项目名称:uwosh.default,代码行数:6,代码来源:subscribers.py

示例14: IsoTime

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
def IsoTime(context):
    import DateTime
    d = DateTime.now()
    return DateTime.ISO.str(d)
开发者ID:coowoole,项目名称:gaedav,代码行数:6,代码来源:BuiltInExtFunctions.py

示例15: _dateConvertToDB

# 需要导入模块: import DateTime [as 别名]
# 或者: from DateTime import now [as 别名]
def _dateConvertToDB(dt):
    if dt == PyDBI.SYSDATE:
        dt = DateTime.now()
    return '%04d%02d%02d%02d%02d%02d' % (dt.year, dt.month, dt.day,
                                         dt.hour, dt.minute, dt.second)
开发者ID:BackupTheBerlios,项目名称:skunkweb-svn,代码行数:7,代码来源:mysqlconn.py


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