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


Python datetime.datetime方法代码示例

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


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

示例1: getGeneralizedTime

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def getGeneralizedTime(cls, dateString):
        year = int(dateString[0:4])
        month = int(dateString[4:6])
        day = int(dateString[6:8])
        hour = int(dateString[8:10])
        minute = int(dateString[10:12])
        #If UTC time.
        if dateString.endsWith("Z"):
            if len(dateString) > 13:
                second = int(dateString[12:14])
            return datetime(year, month, day, hour, minute, second, 0, tzinfo=GXTimeZone(0))

        if len(dateString) > 17:
            second = int(dateString.substring(12, 14))
        tz = dateString[dateString.length() - 4:]
        return datetime(year, month, day, hour, minute, second, 0, tzinfo=GXTimeZone(tz)) 
开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:18,代码来源:_GXCommon.py

示例2: __getDateTime

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def __getDateTime(cls, value):
        dt = None
        if isinstance(value, (GXDateTime)):
            dt = value
        elif isinstance(value, (datetime, str)):
            dt = GXDateTime(value)
            dt.skip |= DateTimeSkips.MILLISECOND
        else:
            raise ValueError("Invalid date format.")
        return dt

    #
    # Convert date time to DLMS bytes.
    #
    # buff
    # Byte buffer where data is write.
    # value
    # Added value.
    # 
开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:21,代码来源:_GXCommon.py

示例3: test_get_status_summary

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def test_get_status_summary(mock_trial_results):
    """Test the status summary based on the trial results."""
    expected = {
        "SURVIVED": 1,
        "DETECTED": 1,
        "ERROR": 1,
        "UNKNOWN": 1,
        "TIMEOUT": 1,
        "TOTAL RUNS": 5,
        "RUN DATETIME": str(datetime(2019, 1, 1)),
    }

    result = get_status_summary(mock_trial_results)
    print(expected)

    assert result == expected 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:18,代码来源:test_report.py

示例4: timestamp_parameter

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def timestamp_parameter(timestamp, allow_none=True):

    if timestamp is None:
        if allow_none:
            return None
        raise ValueError("Timestamp value cannot be None")

    if isinstance(timestamp, datetime):
        return timestamp.isoformat()

    if isinstance(timestamp, basestring):
        if not ISO_8601.match(timestamp):
            raise ValueError(("Invalid timestamp: %s is not a valid ISO-8601"
                              " formatted date") % timestamp)
        return timestamp

    raise ValueError("Cannot accept type %s for timestamp" % type(timestamp)) 
开发者ID:kislyuk,项目名称:aegea,代码行数:19,代码来源:utils.py

示例5: ensure_datetime

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def ensure_datetime(obj):
    """Return the object if it is a datetime-like object

    Parameters
    ----------
    obj : Object to be tested.

    Returns
    -------
    The original object if it is a datetime-like object

    Raises
    ------
    TypeError if `obj` is not datetime-like
    """
    _VALID_TYPES = (str, datetime.datetime, cftime.datetime,
                    np.datetime64)
    if isinstance(obj, _VALID_TYPES):
        return obj
    raise TypeError("datetime-like object required.  "
                    "Type given: {}".format(type(obj))) 
开发者ID:spencerahill,项目名称:aospy,代码行数:23,代码来源:times.py

示例6: datetime_or_default

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def datetime_or_default(date, default):
    """Return a datetime-like object or a default.

    Parameters
    ----------
    date : `None` or datetime-like object or str
    default : The value to return if `date` is `None`

    Returns
    -------
    `default` if `date` is `None`, otherwise returns the result of
    `utils.times.ensure_datetime(date)`

    """
    if date is None:
        return default
    else:
        return ensure_datetime(date) 
开发者ID:spencerahill,项目名称:aospy,代码行数:20,代码来源:times.py

示例7: recursive_test_params

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def recursive_test_params():
    basic_params = {
        'proj': example_proj,
        'model': example_model,
        'run': example_run,
        'var': condensation_rain,
        'date_range': (datetime.datetime(4, 1, 1),
                       datetime.datetime(6, 12, 31)),
        'intvl_in': 'monthly',
        'dtype_in_time': 'ts'
    }
    recursive_params = basic_params.copy()

    recursive_condensation_rain = Var(
        name='recursive_condensation_rain',
        variables=(precip, convection_rain), func=lambda x, y: x - y,
        def_time=True)
    recursive_params['var'] = recursive_condensation_rain

    yield (basic_params, recursive_params)

    _clean_test_direcs() 
开发者ID:spencerahill,项目名称:aospy,代码行数:24,代码来源:test_calc_basic.py

示例8: download_bill

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def download_bill(self, bill_date, bill_type="ALL", device_info=None):
        """
        下载对账单

        :param bill_date: 下载对账单的日期
        :param bill_type: 账单类型,ALL,返回当日所有订单信息,默认值
                          SUCCESS,返回当日成功支付的订单,
                          REFUND,返回当日退款订单,
                          REVOKED,已撤销的订单
        :param device_info: 微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单
        :return: 返回的结果数据
        """
        if isinstance(bill_date, (datetime, date)):
            bill_date = bill_date.strftime("%Y%m%d")

        data = {
            "appid": self.appid,
            "bill_date": bill_date,
            "bill_type": bill_type,
            "device_info": device_info,
        }
        return self._post("pay/downloadbill", data=data) 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:24,代码来源:tools.py

示例9: download_fundflow

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def download_fundflow(self, bill_date, account_type="Basic", tar_type=None):
        """
        下载资金账单
        https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_18&index=7

        :param bill_date: 下载对账单的日期
        :param account_type: 账单的资金来源账户
                             Basic  基本账户
                             Operation 运营账户
                             Fees 手续费账户
        :param tar_type: 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。
                         不传则默认为数据流形式。
        """
        if isinstance(bill_date, (datetime, date)):
            bill_date = bill_date.strftime("%Y%m%d")

        data = {
            "appid": self.appid,
            "bill_date": bill_date,
            "account_type": account_type,
            "sign_type": "HMAC-SHA256",
        }
        if tar_type is not None:
            data["tar_type"] = tar_type
        return self._post("pay/downloadfundflow", data=data) 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:27,代码来源:tools.py

示例10: get_records

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def get_records(self, start_time, end_time, msgid=1, number=10000):
        """
        获取客服聊天记录

        :param start_time: 查询开始时间,UNIX 时间戳
        :param end_time: 查询结束时间,UNIX 时间戳,每次查询不能跨日查询
        :param msgid: 消息id顺序从小到大,从1开始
        :param number: 每次获取条数,最多10000条

        :return: 返回的 JSON 数据包
        """
        if isinstance(start_time, datetime.datetime):
            start_time = time.mktime(start_time.timetuple())
        if isinstance(end_time, datetime.datetime):
            end_time = time.mktime(end_time.timetuple())
        record_data = {
            "starttime": int(start_time),
            "endtime": int(end_time),
            "msgid": msgid,
            "number": number,
        }
        res = self._post("https://api.weixin.qq.com/customservice/msgrecord/getmsglist", data=record_data,)
        return res 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:25,代码来源:customservice.py

示例11: list_statistics

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def list_statistics(self, begin_date, end_date, shop_id=-1):
        """
        Wi-Fi数据统计

        详情请参考
        http://mp.weixin.qq.com/wiki/8/dfa2b756b66fca5d9b1211bc18812698.html

        :param begin_date: 起始日期时间,最长时间跨度为30天
        :param end_date: 结束日期时间戳,最长时间跨度为30天
        :param shop_id: 可选,门店 ID,按门店ID搜索,-1为总统计
        :return: 返回的 JSON 数据包
        """
        if isinstance(begin_date, (datetime, date)):
            begin_date = begin_date.strftime("%Y-%m-%d")
        if isinstance(end_date, (datetime, date)):
            end_date = end_date.strftime("%Y-%m-%d")
        res = self._post(
            "statistics/list",
            data={"begin_date": begin_date, "end_date": end_date, "shop_id": shop_id},
            result_processor=lambda x: x["data"],
        )
        return res 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:24,代码来源:wifi.py

示例12: test_qualification_verify_fail_event

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def test_qualification_verify_fail_event(self):
        from wechatpy.events import QualificationVerifyFailEvent

        xml = """
        <xml>
        <ToUserName><![CDATA[toUser]]></ToUserName>
        <FromUserName><![CDATA[FromUser]]></FromUserName>
        <CreateTime>1442401156</CreateTime>
        <MsgType><![CDATA[event]]></MsgType>
        <Event><![CDATA[qualification_verify_fail]]></Event>
        <FailTime>1442401122</FailTime>
        <FailReason><![CDATA[by time]]></FailReason>
        </xml>"""
        event = parse_message(xml)
        self.assertTrue(isinstance(event, QualificationVerifyFailEvent))
        self.assertTrue(isinstance(event.fail_time, datetime))
        self.assertEqual(event.fail_reason, "by time") 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:19,代码来源:test_events.py

示例13: test_naming_verify_fail_event

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def test_naming_verify_fail_event(self):
        from wechatpy.events import NamingVerifyFailEvent

        xml = """
        <xml>
        <ToUserName><![CDATA[toUser]]></ToUserName>
        <FromUserName><![CDATA[FromUser]]></FromUserName>
        <CreateTime>1442401061</CreateTime>
        <MsgType><![CDATA[event]]></MsgType>
        <Event><![CDATA[naming_verify_fail]]></Event>
        <FailTime>1442401061</FailTime>
        <FailReason><![CDATA[by time]]></FailReason>
        </xml>"""
        event = parse_message(xml)
        self.assertTrue(isinstance(event, NamingVerifyFailEvent))
        self.assertTrue(isinstance(event.fail_time, datetime))
        self.assertEqual(event.fail_reason, "by time") 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:19,代码来源:test_events.py

示例14: update

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def update(self):
        self.data['events'] = []
        self.tzutc = tz.tzutc()
        self.tzlocal = tz.tzlocal()
        urls, colors = [], {}
        for cal in self._iter_calendars():
            urls.append(cal.url)
            colors[cal.url] = cal.color
        for result in utils.iter_responses(urls, timeout=5):
            response = result.get('response')
            if response:
                ical = Calendar.from_ical(response.read().decode('utf-8'))
                color = colors[result.get('url')]
                self.data['events'] += self._parse_events(ical, color)
        self.data['events'] = sorted(self.data['events'], key=lambda e:e['start'])
        # Calculate time to next event
        now = datetime.datetime.now()
        next = [e for e in self.data['events'] if e['start'] > now][0]['start'] if self.data['events'] else self.DELTANONE
        if next < now + datetime.timedelta(seconds=self.DEFAULT_INTERVAL*1.5): self.data['next'] = 'Now'
        else: self.data['next'] = utils.natural_time(next-now, 1)
        super(Plugin, self).update() 
开发者ID:pkkid,项目名称:pkmeter,代码行数:23,代码来源:gcal.py

示例15: _parse_events

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import datetime [as 别名]
def _parse_events(self, ical, color):
        events = []
        today = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
        title = ical.get('x-wr-calname', ical.get('version', ''))
        for event in ical.walk():
            if event.name == "VEVENT":
                start = self._event_start(event)
                if today <= start <= today + datetime.timedelta(days=14):
                    events.append({
                        'title': event.get('summary'),
                        'calendar': title,
                        'color': color,
                        'start': start,
                        'where': event.get('location'),
                        'status': event.get('description'),
                    })
        return events 
开发者ID:pkkid,项目名称:pkmeter,代码行数:19,代码来源:gcal.py


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