Javascript 以momentjs格式将日期从给定格式转换为yyyy mm dd

Javascript 以momentjs格式将日期从给定格式转换为yyyy mm dd,javascript,momentjs,Javascript,Momentjs,我有这个格式的日期。我使用的是monentjs的format()。 当前mydate的格式为2018-10-11T16:31:27+05:30 let newdate=let newdate=this.state.startDate.format(); 我想以2018-10-22的格式获得这个日期。 我试过用这个 let formatfun=(date)=>{ let x=moment(date,"moment.HTML5_FMT.DATE"); return x

我有这个格式的日期。我使用的是monentjs的format()。 当前mydate的格式为2018-10-11T16:31:27+05:30

let newdate=let newdate=this.state.startDate.format();
我想以2018-10-22的格式获得这个日期。 我试过用这个

let formatfun=(date)=>{
      let x=moment(date,"moment.HTML5_FMT.DATE");
      return x;
    }
但无法到达那里。

const newdate=“2018-10-11T16:31:27+05:30”//this.state.startDate.format();
const formatfun=日期=>{
返回日期。substr(0,10);
}
console.log(formatfun(newdate))你试过这个吗

let formatfun=(date)=>{
  let x=moment(date).format("YYYY-MM-DD");
  return x;
}
你可以了解更多关于

let formatfun=(日期)=>{
设x=时刻(日期).format('YYYY-MM-DD');
返回x;
}
let date='2018-10-22T16:31:27+05:30';
控制台日志(日期);
console.log(formatfun(日期))
试试这种方法

时刻(“你的日期”、“日期格式”)。格式(“新格式”)

阅读更多信息:

您可以使用矩(newdate).format(“YYYY-MM-DD”)

请检查以下url以获取更多参考:-

let formatfun=(date)=>{
      let x=moment(date,"moment.HTML5_FMT.DATE").format('yyyy-dd-mm');
      return x;
}