Skip to Content

Conversion of specific time format

Hi,

I received this format from my Odata_service

Thu Mar 16 2017 19:30:00 GMT+0100 (W. Europe Standard Time)

I would like to convert it into standard datatype like below

9/03/2017

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jan 15 at 12:30 PM

    Hi Eric

    I just create a function for all my date conversions, here is an example of what you can do:

    // Format dates
    	formatDate: function(format, date){
    		//var d = new Date(),
    		var d = date,
    		month = '' + this.addZero((d.getMonth() + 1)),
    		day = '' + this.addZero(d.getDate()),
    		year = d.getFullYear(),
    		yearShort = d.getFullYear().toString().substr(-2),
    		hour = this.addZero(d.getHours()),
    		min = this.addZero(d.getMinutes()),
    		sec = this.addZero(d.getSeconds());
    					        
    		switch(format){
    			case "display" : {
    				return [year, month, day].join('-'); // returns "2016-08-01"
    			}
    			break;
    			case "simple" : {
    				return [year, month, day].join(''); // returns "20160801"
    			}
    			break;
    			case "slash" : {
    				return [day, month, year].join('/'); // returns "01/08/2016"
    			}
    			break;
    			case "odata" : {
    				return [year, month, day].join('-') + "T00:00:00"; // returns "2017-08-16T00:00:00"
    			}
    			break;
    		};				        
    	},
    

    Hope this helped :)

    Regards

    Antonette

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 15 at 02:46 PM

    I thank you Antonnette

    Add comment
    10|10000 characters needed characters exceeded