代码之家  ›  专栏  ›  技术社区  ›  Oli

日期格式如下:3月1日,星期一

  •  0
  • Oli  · 技术社区  · 15 年前

    我想做的是: <Full day>, <Day of month><Ordinal> <Month>

    在哪里? <Ordinal> st , nd , rd th

    2 回复  |  直到 15 年前
        1
  •  5
  •   Manoj Govindan    15 年前

    更新2 :看起来OP发现这个很有用:)

    更新 :没关系。警察在找 日期格式,而不是Python。

    my_date.strftime('%A, %d %B')
    

    我发现 this solution 在web上:

    if 4 <= day <= 20 or 24 <= day <= 30:
        suffix = "th"
    else:
        suffix = ["st", "nd", "rd"][day % 10 - 1]
    
        2
  •  4
  •   laffuste user5637641    10 年前

    in the docs . 天知道为什么他们没有链接到从每一个引用到日期格式。

    {{e.when|date:"l, jS F"}}
    

    from django.utils import dateformat
    dateformat.format(datetime.now(), 'l, jS F')