想以Jan,Mar,....的形式获得月份的名称。使用JS

时间:2018-04-23 08:07:44

标签: javascript html node.js

  var today = new Date();
  //$('#timeStampID').val(today.getFullYear() + '-' + 
    ('0' + (today.getMonth() + 1)).slice(-2) + '-' + ('0' + 
    today.getDate()).slice(-2));
  $('#timeStampID').val(String(('0' + 
    today.getDate()).slice(-2)) + ' ' + 
    String(('0' + (today.getMonth() + 1)).slice(-2)) + ' ' + 
    String(today.getFullYear()));

这里我输入的输出文件为:23 04 2018 但我想显示Apr代替04,即月份名称

1 个答案:

答案 0 :(得分:3)

不幸的是,没有一种方法可以将其内置到Date对象中。但你可以这样做:

var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

var monthName = months[today.getMonth()];