Convert yyyy-MM-ddTHH:mm:ss.fffZ to DateTime in JavaScript manually

前端 未结 4 963
没有蜡笔的小新
没有蜡笔的小新 2021-01-02 09:47

I receive from a Webservice a String with a date in this format:

yyyy-MM-ddTHH:mm:ss.fffZ

I need to convert that String with JavaScript to

4条回答
  •  孤独总比滥情好
    2021-01-02 10:18

    momentjs has the answer to this and many other date problems you might have. While it isn't clear where and how you will user the needed date, neither the wanted format, I think momentjs can give you some of the needed tasks I would add the module to my solution and use as (below is parse.com cloud code):

    Parse.Cloud.define("momentFormat", function(request, response){
        var message;
    
        var date = momento('2013-01-08T17:16:36.000Z');
        response.success("original format date: " + date.format("YYYY-MM-DDTHH:mm:ss.SSSZ") + " new format date: " + date.format("ffffdd, MMMM Do YYYY, h:mm:ss a"));
    });
    

    Output:

    {"result":"original format date: 2013-01-08T17:16:36.000+00:00 new format date: Tuesday, January 8th 2013, 5:16:36 pm"}
    

提交回复
热议问题