Change ISO Date String to Date Object - JavaScript

前端 未结 8 1718
花落未央
花落未央 2021-01-01 08:54

I am stuck in a weird situation and unfortunately,even after doing some RnD and googling, i am unable to solve this problem.

I have a date string in ISO format, lik

8条回答
  •  温柔的废话
    2021-01-01 09:48

    You can use "getUTCDate()" to get actual date.

    var d = new Date('2014-11-03T19:38:34.203Z');
    var n = d.getUTCDate();
    

    But it will return only date. to get month "getUTCMonth()" and to get year "getUTCFullYear()". Then construct all in to your format. For example

    var n=[];
    var d = new Date('2014-11-03T19:38:34.203Z');
    var s = d.getUTCDate();
    n.push(s);
    s=d.getUTCMonth();
    n.push(s);
    s=d.getUTCFullYear();
    n.push(s);
    

    Finally make n as an object.

提交回复
热议问题