【问题标题】:How to extract only date from moment object如何仅从时刻对象中提取日期
【发布时间】:2016-02-22 06:12:17
【问题描述】:

我正在使用时刻对象作为日期。 为此我写了

dateOnly = moment(date.format("MM/DD/YYYY"));
var ndate = dateOnly.toDate();

我只想在前端显示日期,但它以我不想要的这种格式显示

2016 年 2 月 22 日星期一 00:00:00 GMT+0530(印度标准时间)

【问题讨论】:

    标签: javascript


    【解决方案1】:

    您可以使用时刻的格式功能以您想要的格式显示日期

    moment().format('MM/DD/YYYY'); // "02/22/2016"
    

    您可以在这里浏览所有可用的格式

    http://momentjs.com/docs/#/displaying/

    【讨论】:

      【解决方案2】:
      var dateOnly = moment(date).format('MM/DD/YYYY'); // for formatted dates.
      yesterday= moment(date).subtract(1,'days') // for previous day 
      //you can replace days with months and years.
      tomorrow= moment(date).add(1,'days') // for upcoming day 
      //you can replace days with months and years. 
      var date1= moment(yesterday)
      var date2= moment(tomorrow)
      differencebetweenmoments =moment(date1).diff(moment(date2),'days');
      

      【讨论】:

        猜你喜欢
        • 2018-10-12
        • 2017-04-05
        • 1970-01-01
        • 1970-01-01
        • 2020-01-21
        • 1970-01-01
        • 2017-09-04
        • 2015-03-14
        • 2016-02-23
        相关资源
        最近更新 更多