cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion of specific time format

chambikilo08
Explorer
0 Kudos

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

View Entire Topic
antonette_oberholster
Active Contributor
0 Kudos

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