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

使用力矩库设置日期格式

  •  0
  • heyr  · 技术社区  · 6 年前
                  data() {
                return {
    
                  date: Moment().format("llll"),
                  console.log(date)
            }
           }
    

    我试图实现的格式类型是:周一,7月2日,但是通过目前为止我已经实现的内容,我得到了:周一,7月2日,2018 5:08 pm。 我目前正在使用即时日期库 https://momentjs.com/ . 但是我要找的那个没有在文档中列出。

    2 回复  |  直到 6 年前
        1
  •  3
  •   BenM    6 年前

    格式相当简单 in the docs 在Moment的网站上。很容易为你的例子找出正确的答案。以下是您需要的:

    moment().format('ddd, D MMM');
    
        2
  •  0
  •   Matteo Pieroni    6 年前

    不清楚你为什么要用“llll”来格式化日期。

    如果是为了 区域设置 当使用对象实例化区域设置(例如法语)时,可以重写这些设置:

    moment.locale('fr', {
        longDateFormat : {
            LLLL : 'ddd, D MMM'
        }
    }
    

    然后将日期返回为

    Moment().format("LLLL")
    

    如果您没有使用特定的区域设置 你可以去做本姆写的。