當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。