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


Python datetime.time方法代码示例

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


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

示例1: isTradeAvailable

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def isTradeAvailable(self):
        # 매수 가능 시간 체크 
        # 기본 정보를 얻기 위해서는 장 시작전 미리 동작을 시켜야 하고 매수를 위한 시간은 정확히 9시를 맞춤 (동시호가 시간의 매도 호가로 인해 매수 됨을 막기 위함)
        ret_vals= []
        current_time = self.currentTime.time()
        for start, stop in AUTO_TRADING_OPERATION_TIME:
            start_time =  datetime.time(
                            hour = 9,
                            minute = 0 )
            stop_time =   datetime.time( 
                            hour = stop[0],
                            minute = stop[1])
            if( current_time >= start_time and current_time <= stop_time ):
                ret_vals.append(True)
            else:
                ret_vals.append(False)
                pass

        # 하나라도 True 였으면 거래 가능시간임  
        if( ret_vals.count(True) ):
            return True
        else:
            return False
        pass 
开发者ID:coreanq,项目名称:kw_condition,代码行数:26,代码来源:main.py

示例2: remove_old_files

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def remove_old_files(directory, filetype):
    now = datetime.datetime.now()
    now_time = now.time()
    # time between which each day the deletion is done
    if datetime.time(06, 30) <= now_time <= datetime.time(20, 35):
        # data directory path
        data_file_path = directory
        # data_file_path = os.path.join(homepath,datadir)
        now = time.time()
        for f in os.listdir(data_file_path):
            data_file = os.path.join(data_file_path, f)
            # check files older than 3 days
            if os.stat(data_file).st_mtime < now - 2 * 86400:
                # only delete csv files
                if filetype is None:
                    if os.path.isfile(data_file):
                        os.remove(data_file)
                else:
                    if str(filetype) in str(os.path.splitext(data_file)[1]):
                        # print data_file
                        if os.path.isfile(data_file):
                            os.remove(data_file) 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:24,代码来源:collectdReportMetrics.py

示例3: test_decode_time

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def test_decode_time():
    assert _decode_time('03:04:05', True) == time(3, 4, 5, tzinfo=timezone(timedelta(0)))
    # TODO: The standard specifies that the second fraction is limited to one
    # digit, however udatetime only permits 3 or 6 digits.
    assert _decode_time('03:04:05.600', True) == time(3, 4, 5, 600000, tzinfo=timezone(timedelta(0)))
    assert _decode_time('03:04:05Z', True) == time(3, 4, 5, tzinfo=timezone(timedelta(0)))
    assert _decode_time('03:04:05+00:00', True) == time(3, 4, 5, tzinfo=timezone(timedelta(0)))
    assert _decode_time('03:04:05-00:00', True) == time(3, 4, 5, tzinfo=timezone(timedelta(0)))
    assert _decode_time('03:04:05+07:08', True) == time(3, 4, 5, tzinfo=timezone(timedelta(hours=7, minutes=8)))
    assert _decode_time('03:04:05-07:08', True) == time(3, 4, 5, tzinfo=timezone(timedelta(hours=-7, minutes=-8)))
    assert _decode_time('03:04:05.600+07:08', True) == \
           time(3, 4, 5, 600000, tzinfo=timezone(timedelta(hours=7, minutes=8)))
    assert _decode_time('03:04:05', False) == time(3, 4, 5)
    assert _decode_time('03:04:05.600', False) == time(3, 4, 5, 600000)
    assert _decode_time('03:04:05Z', False) == time(3, 4, 5)
    assert _decode_time('03:04:05+00:00', False) == time(3, 4, 5)
    assert _decode_time('03:04:05-00:00', False) == time(3, 4, 5)
    assert _decode_time('12:00:00+07:08', False) == time(4, 52)
    assert _decode_time('12:00:00-07:08', False) == time(19, 8) 
开发者ID:opendoor-labs,项目名称:rets,代码行数:21,代码来源:decoder_test.py

示例4: default

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def default(self, o):
    if isinstance(o, datetime.datetime):
      if o.microsecond == 0:
        # If the time doesn't have ms-resolution, leave it out to keep
        # things smaller.
        return "Date(%d,%d,%d,%d,%d,%d)" % (
            o.year, o.month - 1, o.day, o.hour, o.minute, o.second)
      else:
        return "Date(%d,%d,%d,%d,%d,%d,%d)" % (
            o.year, o.month - 1, o.day, o.hour, o.minute, o.second,
            o.microsecond / 1000)
    elif isinstance(o, datetime.date):
      return "Date(%d,%d,%d)" % (o.year, o.month - 1, o.day)
    elif isinstance(o, datetime.time):
      return [o.hour, o.minute, o.second]
    else:
      return super(DataTableJSONEncoder, self).default(o) 
开发者ID:google,项目名称:compare-codecs,代码行数:19,代码来源:gviz_api.py

示例5: make_json_safe

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def make_json_safe(obj):
    """
    Makes an object json serializable.
    This is designed to take a list or dictionary,
    and is fairly limited.  This is primarily for
    the managers when creating objects.

    :param object obj:
    :return: The json safe dictionary.
    :rtype: object|six.text_type|list|dict
    """
    if isinstance(obj, dict):
        for key, value in six.iteritems(obj):
            obj[key] = make_json_safe(value)
    elif isinstance(obj, (list, set, tuple,)):
        response = []
        for val in obj:
            response.append(make_json_safe(val))
        return response
    elif isinstance(obj, (datetime.datetime, datetime.date, datetime.time, datetime.timedelta)):
        obj = six.text_type(obj)
    elif isinstance(obj, decimal.Decimal):
        obj = float(obj)
    return obj 
开发者ID:vertical-knowledge,项目名称:ripozo,代码行数:26,代码来源:utilities.py

示例6: set_from_reporting_config_json

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def set_from_reporting_config_json():
    # global hostname, hostnameShort
    report_file_name = "reporting_config.json"

    # reading file form reporting_config.json
    with open(os.path.join(home_path, report_file_name), 'r') as f:
        config = json.load(f)

    reporting_interval_string = config['reporting_interval']
    # is_second_reporting = False
    if reporting_interval_string[-1:] == 's':
        # is_second_reporting = True
        reporting_interval_l = float(config['reporting_interval'][:-1])
        reporting_interval_l = float(reporting_interval_l / 60)
    else:
        reporting_interval_l = int(config['reporting_interval'])

    # keep_file_days = int(config['keep_file_days'])
    prev_endtime_l = config['prev_endtime']
    # deltaFields_l = config['delta_fields']

    hostname_l = socket.getfqdn()
    hostname_short_l = socket.gethostname().partition(".")[0]
    csvpath_l = "/var/lib/collectd/csv/" + hostname_short_l

    if not os.path.exists(csvpath_l):
        csvpath_l = "/var/lib/collectd/csv/" + hostname_l
    if not os.path.exists(csvpath_l):
        directory_list = os.listdir("/var/lib/collectd/csv")
        if len(directory_list) > 0:
            csvpath_l = "/var/lib/collectd/csv/" + directory_list[0]

    date_l = time.strftime("%Y-%m-%d")
    return reporting_interval_l, hostname_l, hostname_short_l, prev_endtime_l, csvpath_l, date_l


# deletes old csv files from a directory 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:39,代码来源:collectdReportMetrics.py

示例7: set_epoch_time

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def set_epoch_time(reporting_interval_l, prev_endtime_l):
    if prev_endtime_l != "0":
        start_time = prev_endtime_l
        # pad a second after prev_end_time
        start_time_epoch_l = 1000 + long(1000 * time.mktime(time.strptime(start_time, "%Y%m%d%H%M%S")))
        # end_time_epoch = start_time_epoch_l + 1000 * 60 * reporting_interval_l
        start_time_epoch_l = start_time_epoch_l / 1000
    else:  # prev_endtime == 0
        end_time_epoch = int(time.time()) * 1000
        start_time_epoch_l = end_time_epoch - 1000 * 60 * reporting_interval_l
        start_time_epoch_l = start_time_epoch_l / 1000
    return reporting_interval_l, start_time_epoch_l, prev_endtime_l


# update prev_endtime in config file 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:17,代码来源:collectdReportMetrics.py

示例8: update_endtime_in_config

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def update_endtime_in_config(metric_data_l, reporting_interval_l, new_prev_endtime_epoch_l, hostname_l):
    if new_prev_endtime_epoch_l == 0:
        print "No data is reported"
    else:
        new_prev_endtimeinsec = math.ceil(long(new_prev_endtime_epoch_l) / 1000.0)
        new_prev_endtime = time.strftime(
            "%Y%m%d%H%M%S", time.localtime(long(new_prev_endtimeinsec)))
        update_timestamp(new_prev_endtime)
        send_data(metric_data_l, reporting_interval_l, hostname_l)
    return 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:12,代码来源:collectdReportMetrics.py

示例9: __force_datetime

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def __force_datetime(self, obj):
        """Converts ojb to time.datetime.datetime

        YAML parsing returns either date or datetime object depending
        on how the date is written. YYYY-MM-DD will return a date and
        YYYY-MM-DDThh:mm:ss will return a datetime

        :param obj: date or datetime object
        """
        if isinstance(obj, datetime.datetime):
            return obj

        t = datetime.time(0, 0)
        return datetime.datetime.combine(obj, t) 
开发者ID:chaoss,项目名称:grimoirelab-sortinghat,代码行数:16,代码来源:grimoirelab.py

示例10: time_diff

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def time_diff(self, time1,time2):
        '''
        *
        * Getting the offest by comparing both times from the unix epoch time and getting the difference.
        *
        '''
        timeA = datetime.datetime.strptime(time1, '%I:%M:%S %p')
        timeB = datetime.datetime.strptime(time2, '%I:%M:%S %p')
        timeAEpoch = calendar.timegm(timeA.timetuple())
        timeBEpoch = calendar.timegm(timeB.timetuple())
        tdelta = abs(timeAEpoch) - abs(timeBEpoch)
        return int(tdelta/60) 
开发者ID:justinemter,项目名称:pseudo-channel,代码行数:14,代码来源:PseudoChannel.py

示例11: get_end_time_from_duration

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def get_end_time_from_duration(self, startTime, duration):

        time = datetime.datetime.strptime(startTime, '%I:%M:%S %p')
        show_time_plus_duration = time + datetime.timedelta(milliseconds=duration)
        return show_time_plus_duration 
开发者ID:justinemter,项目名称:pseudo-channel,代码行数:7,代码来源:PseudoChannel.py

示例12: generate_memory_schedule

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def generate_memory_schedule(schedulelist, isforupdate=False):

            print "##### Generating Memory Schedule."
            now = datetime.datetime.now()
            now = now.replace(year=1900, month=1, day=1)
            pseudo_cache = pseudo_channel.get_daily_schedule_cache_as_json()
            prev_end_time_to_watch_for = None
            if pseudo_channel.USE_OVERRIDE_CACHE and isforupdate:
                for cached_item in pseudo_cache:
                    prev_start_time = datetime.datetime.strptime(cached_item[8], "%I:%M:%S %p")
                    try:
                        prev_end_time = datetime.datetime.strptime(cached_item[9], '%Y-%m-%d %H:%M:%S.%f')
                    except ValueError:
                        prev_end_time = datetime.datetime.strptime(cached_item[9], '%Y-%m-%d %H:%M:%S')
                    """If update time is in between the prev media start / stop then there is overlap"""
                    if prev_start_time < now and prev_end_time > now:
                        try:
                            print "+++++ It looks like there is update schedule overlap", cached_item[3]
                        except:
                            pass
                        prev_end_time_to_watch_for = prev_end_time
            for item in schedulelist:
                trans_time = datetime.datetime.strptime(item[8], "%I:%M:%S %p").strftime("%H:%M")
                new_start_time = datetime.datetime.strptime(item[8], "%I:%M:%S %p")
                if prev_end_time_to_watch_for == None:
                    schedule.every().day.at(trans_time).do(job_that_executes_once, item, schedulelist).tag('daily-tasks')
                else:
                    """If prev end time is more then the start time of this media, skip it"""
                    if prev_end_time_to_watch_for > new_start_time:
                        try:
                            print "Skipping scheduling item do to cached overlap.", item[3]
                        except:
                            pass
                        continue
                    else:
                        schedule.every().day.at(trans_time).do(job_that_executes_once, item, schedulelist).tag('daily-tasks')
            print "+++++ Done." 
开发者ID:justinemter,项目名称:pseudo-channel,代码行数:39,代码来源:PseudoChannel.py

示例13: to_xml

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def to_xml(self, pretty=False, query=None):
        '''
        Export window definition to XML

        Parameters
        ----------
        pretty : bool, optional
            Should the output include whitespace for readability?
        query : ContinuousQuery, optional
            The parent query object of this window

        Examples
        --------
        >>> win.to_xml(pretty=True)
        <window-source insert-only="true" name="w_data">
          <schema>
            <fields>
              <field key="true" name="id" type="int64" />
              <field key="false" name="time" type="double" />
            </fields>
          </schema>
        </window-source>

        Returns
        -------
        string

        '''
        return xml.to_xml(self.to_element(query=query), pretty=pretty) 
开发者ID:sassoftware,项目名称:python-esppy,代码行数:31,代码来源:base.py

示例14: _decode_time

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def _decode_time(value: str, include_tz: bool) -> time:
    decoded = _decode_datetime('1970-01-01T' + value, include_tz)
    return decoded.time().replace(tzinfo=decoded.tzinfo) 
开发者ID:opendoor-labs,项目名称:rets,代码行数:5,代码来源:decoder.py

示例15: ToString

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import time [as 别名]
def ToString(value):
    if value is None:
      return "(empty)"
    elif isinstance(value, (datetime.datetime,
                            datetime.date,
                            datetime.time)):
      return str(value)
    elif isinstance(value, unicode):
      return value
    elif isinstance(value, bool):
      return str(value).lower()
    else:
      return str(value).decode("utf-8") 
开发者ID:google,项目名称:compare-codecs,代码行数:15,代码来源:gviz_api.py


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