Parse 'Date & Time' string in Javascript which are of custom format

前端 未结 5 1137
-上瘾入骨i
-上瘾入骨i 2020-11-30 10:08

I have to parse a date and time string of format \"2015-01-16 22:15:00\". I want to parse this into JavaScript Date Object. Any help on this?

I tried some jquery plu

5条回答
  •  借酒劲吻你
    2020-11-30 10:51

    I was trying to use moment.js guys. But since I was having this error, "ReferenceError: moment is not defined", I had to skip it for now. I am using an temporary workaround for now.

    function parseDate(dateString) {
        var dateTime = dateString.split(" ");
        var dateOnly = dateTime[0];
        var timeOnly = dateTime[1];
    
        var temp = dateOnly + "T" + timeOnly;
        return new Date(temp);
    }
    

提交回复
热议问题