search

Home  >  Q&A  >  body text

javascript - How to quickly convert CST time into timestamp

Thu Jun 15 2017 14:35:48 GMT+0800 (CST)

For example, for a time like this, I am currently using the VUE element plug-in. I don’t know why the time comes out in this format. Is there a simpler conversion method?

女神的闺蜜爱上我女神的闺蜜爱上我2737 days ago987

reply all(1)I'll reply

  • 学习ing

    学习ing2017-06-26 10:55:32

    new Date('Thu Jun 15 2017 14:35:48 GMT+0800 (CST)').getTime()
    Attach a function

    function parseTime (timeStamp, format) {
        var date = new Date(timeStamp);
        var o = {
            'M+' : date.getMonth() + 1, //month
            'D+' : date.getDate(), //day
            'h+' : date.getHours(), //hour
            'm+' : date.getMinutes(), //minute
            's+' : date.getSeconds(), //second
            'S' : date.getMilliseconds() //millisecond
        }
    
        if(/(Y+)/.test(format)) {
            format = format.replace(RegExp.,
                (date.getFullYear() + '').substr(4 - RegExp..length));
        }
    
        for(var k in o) {
            if (new RegExp('('+ k +')').test(format)) {
                format = format.replace(RegExp.,
                    RegExp..length == 1 ? o[k] : ('00'+ o[k]).substr((''+ o[k]).length));
            }
        }
        return format;
    }
    // usage
    parseTime(new Date.getTime(), 'hh:mm')

    reply
    0
  • Cancelreply