Skip to Content
0

Conversion of specific time format

Jan 15 at 11:52 AM

35

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Antonette Venter Jan 15 at 12:30 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Eric Ntomo Jan 15 at 02:46 PM
0

I thank you Antonnette

Share
10 |10000 characters needed characters left characters exceeded