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


Python datetime.isoformat方法代码示例

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


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

示例1: __init__

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import isoformat [as 别名]
def __init__(self,
                 external_dag_id,
                 external_task_id,
                 execution_date: Optional[Union[str, datetime.datetime]] = "{{ execution_date.isoformat() }}",
                 recursion_depth: int = 10,
                 *args,
                 **kwargs):
        super().__init__(*args, **kwargs)
        self.external_dag_id = external_dag_id
        self.external_task_id = external_task_id
        if isinstance(execution_date, datetime.datetime):
            self.execution_date = execution_date.isoformat()
        elif isinstance(execution_date, str):
            self.execution_date = execution_date
        else:
            raise TypeError('Expected str or datetime.datetime type for execution_date. Got {}'
                            .format(type(execution_date)))
        if recursion_depth <= 0:
            raise ValueError("recursion_depth should be a positive integer")
        self.recursion_depth = recursion_depth 
开发者ID:apache,项目名称:airflow,代码行数:22,代码来源:external_task_sensor.py

示例2: timestamp_str

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import isoformat [as 别名]
def timestamp_str(self,
                      tz: Optional[datetime.tzinfo] = None,
                      timespec: str = 'auto') -> str:
        """Return a string for the calibration timestamp.

        Args:
            tz: The timezone for the string. If None, the method uses the
                platform's local date and time.
            timespec: See datetime.isoformat for valid values.

        Returns:
            The string in ISO 8601 format YYYY-MM-DDTHH:MM:SS.ffffff.
        """
        dt = datetime.datetime.fromtimestamp(self.timestamp / 1000, tz)
        dt += datetime.timedelta(microseconds=self.timestamp % 1000000)
        return dt.isoformat(sep=' ', timespec=timespec) 
开发者ID:quantumlib,项目名称:Cirq,代码行数:18,代码来源:calibration.py

示例3: add_microseconds

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import isoformat [as 别名]
def add_microseconds(timestamp, microseconds):
    """
    Add given microseconds to a timestamp.

    Input and output are timestamps as ISO format strings.  Microseconds can be negative.
    """
    # First try to parse the timestamp string and do simple math, to avoid
    # the high cost of using strptime to parse in most cases.
    timestamp_base, _period, microsec_base = timestamp.partition('.')
    if not microsec_base:
        microsec_base = '0'
        timestamp = ensure_microseconds(timestamp)
    microsec_int = int(microsec_base) + microseconds
    if microsec_int >= 0 and microsec_int < 1000000:
        return "{}.{}".format(timestamp_base, str(microsec_int).zfill(6))

    # If there's a carry, then just use the datetime library.
    parsed_timestamp = datetime.datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%f')
    newtimestamp = (parsed_timestamp + datetime.timedelta(microseconds=microseconds)).isoformat()
    return ensure_microseconds(newtimestamp) 
开发者ID:edx,项目名称:edx-analytics-pipeline,代码行数:22,代码来源:datetime_util.py

示例4: test_datetime

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import isoformat [as 别名]
def test_datetime(self):
        """
        Test that a model with a datetime and date field is handled correctly
        """
        financial_aid = FinancialAidFactory.create(justification=None)
        assert serialize_model_object(financial_aid) == {
            'country_of_income': financial_aid.country_of_income,
            'country_of_residence': financial_aid.country_of_residence,
            'created_on': format_as_iso8601(financial_aid.created_on),
            'date_documents_sent': financial_aid.date_documents_sent.isoformat(),
            'date_exchange_rate': format_as_iso8601(financial_aid.date_exchange_rate),
            'id': financial_aid.id,
            'income_usd': financial_aid.income_usd,
            'justification': None,
            'original_currency': financial_aid.original_currency,
            'original_income': financial_aid.original_income,
            'status': financial_aid.status,
            'tier_program': financial_aid.tier_program.id,
            'updated_on': format_as_iso8601(financial_aid.updated_on),
            'user': financial_aid.user.id,
        } 
开发者ID:mitodl,项目名称:micromasters,代码行数:23,代码来源:utils_test.py

示例5: ensure_microseconds

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import isoformat [as 别名]
def ensure_microseconds(timestamp):
    """
    Make sure timestamp strings contain microseconds, even if zero.

    This is needed after datetime.isoformat() calls, which truncate zero microseconds.
    """
    if '.' not in timestamp:
        return '{datetime}.000000'.format(datetime=timestamp)
    else:
        return timestamp 
开发者ID:edx,项目名称:edx-analytics-pipeline,代码行数:12,代码来源:datetime_util.py

示例6: mysql_datetime_to_isoformat

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import isoformat [as 别名]
def mysql_datetime_to_isoformat(mysql_datetime):
    """
    Convert mysql datetime strings to isoformat standard.

    Mysql outputs strings of the form '2012-07-25 12:26:22.0'.
    Log files use isoformat strings for sorting.
    """
    date_parts = [int(d) for d in re.split(r'[:\-\. ]', mysql_datetime)]
    if len(date_parts) > 6:
        tenths = date_parts[6]
        date_parts[6] = tenths * 100000
    timestamp = datetime.datetime(*date_parts).isoformat()
    return ensure_microseconds(timestamp) 
开发者ID:edx,项目名称:edx-analytics-pipeline,代码行数:15,代码来源:datetime_util.py

示例7: log

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import isoformat [as 别名]
def log(txt, dt=None, data=None):
        dt = dt or data.datetime[0]
        dt = bt.num2date(dt)
        _logger.info('%s, %s' % (dt.isoformat(), txt)) 
开发者ID:wywongbd,项目名称:pairstrade-fyp-2019,代码行数:6,代码来源:ptstrategy.py

示例8: isodatetime

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import isoformat [as 别名]
def isodatetime(s):
    # Reverse of `datetime.isoformat()` besides microseconds & timezones
    return datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%S") 
开发者ID:ooni,项目名称:pipeline,代码行数:5,代码来源:cli.py

示例9: format_as_iso8601

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import isoformat [as 别名]
def format_as_iso8601(time):
    """Helper function to format datetime with the Z at the end"""
    # Can't use datetime.isoformat() because format is slightly different from this
    iso_format = '%Y-%m-%dT%H:%M:%S'
    formatted_time = time.strftime(iso_format)
    if time.microsecond:
        miniseconds_format = '.%f'
        formatted_time += time.strftime(miniseconds_format)[:4]
    return formatted_time + "Z" 
开发者ID:mitodl,项目名称:micromasters,代码行数:11,代码来源:utils_test.py

示例10: poke

# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import isoformat [as 别名]
def poke(self, context, session=None):
        if self.execution_delta:
            dttm = context['execution_date'] - self.execution_delta
        elif self.execution_date_fn:
            dttm = self._handle_execution_date_fn(context=context)
        else:
            dttm = context['execution_date']

        dttm_filter = dttm if isinstance(dttm, list) else [dttm]
        serialized_dttm_filter = ','.join(
            [datetime.isoformat() for datetime in dttm_filter])

        self.log.info(
            'Poking for %s.%s on %s ... ',
            self.external_dag_id, self.external_task_id, serialized_dttm_filter
        )

        DM = DagModel
        # we only do the check for 1st time, no need for subsequent poke
        if self.check_existence and not self.has_checked_existence:
            dag_to_wait = session.query(DM).filter(
                DM.dag_id == self.external_dag_id
            ).first()

            if not dag_to_wait:
                raise AirflowException('The external DAG '
                                       '{} does not exist.'.format(self.external_dag_id))
            else:
                if not os.path.exists(dag_to_wait.fileloc):
                    raise AirflowException('The external DAG '
                                           '{} was deleted.'.format(self.external_dag_id))

            if self.external_task_id:
                refreshed_dag_info = DagBag(dag_to_wait.fileloc).get_dag(self.external_dag_id)
                if not refreshed_dag_info.has_task(self.external_task_id):
                    raise AirflowException('The external task'
                                           '{} in DAG {} does not exist.'
                                           .format(self.external_task_id,
                                                   self.external_dag_id))
            self.has_checked_existence = True

        count_allowed = self.get_count(dttm_filter, session, self.allowed_states)

        count_failed = -1
        if len(self.failed_states) > 0:
            count_failed = self.get_count(dttm_filter, session, self.failed_states)

        session.commit()
        if count_failed == len(dttm_filter):
            if self.external_task_id:
                raise AirflowException('The external task {} in DAG {} failed.'
                                       .format(self.external_task_id, self.external_dag_id))
            else:
                raise AirflowException('The external DAG {} failed.'
                                       .format(self.external_dag_id))

        return count_allowed == len(dttm_filter) 
开发者ID:apache,项目名称:airflow,代码行数:59,代码来源:external_task_sensor.py


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