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


Python dateformat.time_format方法代码示例

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


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

示例1: localize

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import time_format [as 别名]
def localize(value, use_l10n=None):
    """
    Checks if value is a localizable type (date, number...) and returns it
    formatted as a string using current locale format.

    If use_l10n is provided and is not None, that will force the value to
    be localized (or not), overriding the value of settings.USE_L10N.
    """
    if isinstance(value, bool):
        return mark_safe(six.text_type(value))
    elif isinstance(value, (decimal.Decimal, float) + six.integer_types):
        return number_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.datetime):
        return date_format(value, 'DATETIME_FORMAT', use_l10n=use_l10n)
    elif isinstance(value, datetime.date):
        return date_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.time):
        return time_format(value, 'TIME_FORMAT', use_l10n=use_l10n)
    else:
        return value 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:formats.py

示例2: localize

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import time_format [as 别名]
def localize(value, use_l10n=None):
    """
    Check if value is a localizable type (date, number...) and return it
    formatted as a string using current locale format.

    If use_l10n is provided and is not None, it forces the value to
    be localized (or not), overriding the value of settings.USE_L10N.
    """
    if isinstance(value, str):  # Handle strings first for performance reasons.
        return value
    elif isinstance(value, bool):  # Make sure booleans don't get treated as numbers
        return str(value)
    elif isinstance(value, (decimal.Decimal, float, int)):
        return number_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.datetime):
        return date_format(value, 'DATETIME_FORMAT', use_l10n=use_l10n)
    elif isinstance(value, datetime.date):
        return date_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.time):
        return time_format(value, 'TIME_FORMAT', use_l10n=use_l10n)
    return value 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:23,代码来源:formats.py

示例3: localize

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import time_format [as 别名]
def localize(value, use_l10n=None):
    """
    Checks if value is a localizable type (date, number...) and returns it
    formatted as a string using current locale format.

    If use_l10n is provided and is not None, that will force the value to
    be localized (or not), overriding the value of settings.USE_L10N.
    """
    if isinstance(value, six.string_types):  # Handle strings first for performance reasons.
        return value
    elif isinstance(value, bool):  # Make sure booleans don't get treated as numbers
        return mark_safe(six.text_type(value))
    elif isinstance(value, (decimal.Decimal, float) + six.integer_types):
        return number_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.datetime):
        return date_format(value, 'DATETIME_FORMAT', use_l10n=use_l10n)
    elif isinstance(value, datetime.date):
        return date_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.time):
        return time_format(value, 'TIME_FORMAT', use_l10n=use_l10n)
    return value 
开发者ID:Yeah-Kun,项目名称:python,代码行数:23,代码来源:formats.py

示例4: time_format

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import time_format [as 别名]
def time_format(value, format=None, use_l10n=None):
    """
    Formats a datetime.time object using a localizable format

    If use_l10n is provided and is not None, that will force the value to
    be localized (or not), overriding the value of settings.USE_L10N.
    """
    return dateformat.time_format(value, get_format(format or 'TIME_FORMAT', use_l10n=use_l10n)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:10,代码来源:formats.py

示例5: time

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import time_format [as 别名]
def time(value, arg=None):
    """Formats a time according to the given format."""
    if value in (None, ''):
        return ''
    if arg is None:
        arg = settings.TIME_FORMAT
    try:
        return formats.time_format(value, arg)
    except AttributeError:
        try:
            return time_format(value, arg)
        except AttributeError:
            return '' 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:15,代码来源:defaultfilters.py

示例6: time_format

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import time_format [as 别名]
def time_format(value, format=None, use_l10n=None):
    """
    Format a datetime.time object using a localizable format.

    If use_l10n is provided and is not None, it forces the value to
    be localized (or not), overriding the value of settings.USE_L10N.
    """
    return dateformat.time_format(value, get_format(format or 'TIME_FORMAT', use_l10n=use_l10n)) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:10,代码来源:formats.py

示例7: time

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import time_format [as 别名]
def time(value, arg=None):
    """Format a time according to the given format."""
    if value in (None, ''):
        return ''
    try:
        return formats.time_format(value, arg)
    except (AttributeError, TypeError):
        try:
            return time_format(value, arg)
        except (AttributeError, TypeError):
            return '' 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:13,代码来源:defaultfilters.py

示例8: time

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import time_format [as 别名]
def time(value, arg=None):
    """Formats a time according to the given format."""
    if value in (None, ''):
        return ''
    try:
        return formats.time_format(value, arg)
    except (AttributeError, TypeError):
        try:
            return time_format(value, arg)
        except (AttributeError, TypeError):
            return '' 
开发者ID:Yeah-Kun,项目名称:python,代码行数:13,代码来源:defaultfilters.py


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