I have date in format: Thu, 01 Dec 2016 00:00:00 GMT, how to get date of format yyyy-mm-dd from that?
            Asked
            
        
        
            Active
            
        
            Viewed 1,956 times
        
    -2
            
            
         
    
    
        Klimenko Kirill
        
- 634
- 2
- 8
- 22
- 
                    4Really, have you tried anything?? – Durga Sep 19 '17 at 09:42
- 
                    1if you are ok with libraries, you can use moment.js for this – Varun Sharma Sep 19 '17 at 09:42
- 
                    @Durga I don't even know HOW to parse that, so I just ask question. I try to find solution, but didn't find that. Is that problem to ask question, when u can`t find solution? – Klimenko Kirill Sep 19 '17 at 09:43
- 
                    duplicate post of this so post ; https://stackoverflow.com/questions/23593052/format-javascript-date-to-yyyy-mm-dd – Mr. Pyramid Sep 19 '17 at 09:48
- 
                    @Klimenkomud if you search first link only will give you an answer. If you want you can use moment.js instead. `moment('Thu, 01 Dec 2016 00:00:00 GMT').format("YYYY-MM-DD");` – Durga Sep 19 '17 at 09:48
- 
                    For you to know: I just used google with "format date javascript" (that is your issue) and I got plenty of results like [this](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date). You can ask questions here **showing first your effort to try to solve the issue** – Lelio Faieta Sep 19 '17 at 09:53
2 Answers
1
            
            
        If you want to stick to plain JS:
Date.prototype.yyyymmdd = function() {
  var mm = this.getMonth() + 1;
  var dd = this.getDate();
  return [this.getFullYear(),
          (mm>9 ? '' : '0') + mm,
          (dd>9 ? '' : '0') + dd
         ].join('-');
};
 
    
    
        DobromirM
        
- 2,017
- 2
- 20
- 29
0
            
            
        if you want split it
var a = 'Thu, 01 Dec 2016 00:00:00 GMT'
var s = a.split(' ')
console.log(s)
console.log(s[3]+'-'+s[2]+'-'+s[0]) 
    
    
        KEKUATAN
        
- 948
- 7
- 21