How can I convert string to datetime with format specification in JavaScript?

前端 未结 15 1027
终归单人心
终归单人心 2020-11-22 02:35

How can I convert a string to a date time object in javascript by specifying a format string?

I am looking for something like:

var dateTime = convert         


        
15条回答
  •  一生所求
    2020-11-22 03:12

    //Here pdate is the string date time
    var date1=GetDate(pdate);
        function GetDate(a){
            var dateString = a.substr(6);
            var currentTime = new Date(parseInt(dateString ));
            var month =("0"+ (currentTime.getMonth() + 1)).slice(-2);
            var day =("0"+ currentTime.getDate()).slice(-2);
            var year = currentTime.getFullYear();
            var date = day + "/" + month + "/" + year;
            return date;
        }
    

提交回复
热议问题