Remove time from GMT format

I get a date that comes in GMT format, Fri, 18 Oct 2013 11:38:23 GMT. The problem is that time will ruin the schedule I use.

How can I delete everything except the actual date?

+8
javascript date utc gmt
source share
5 answers

Like this:

var dateString='Mon Jan 12 00:00:00 GMT 2015'; dateString=new Date(dateString).toUTCString(); dateString=dateString.split(' ').slice(0, 4).join(' ') console.log(dateString); 
+17
source share

If you want to use Date rather than String, you can do this:

 var d=new Date(); //your date object console.log(new Date(d.setHours(0,0,0,0))); 

-PS, you do not need a new Date object, this is just an example if you want to register it on the console.

http://www.w3schools.com/jsref/jsref_sethours.asp

+11
source share

Just slice it substring :

  var str = 'Fri, 18 Oct 2013 11:38:23 GMT'; str = str.substring(0,tomorrow.toLocaleString().indexOf(':')-3); 
+1
source share

In this case, you can simply manipulate your string without using a Date object.

 var dateTime = 'Fri, 18 Oct 2013 11:38:23 GMT', date = dateTime.split(' ', 4).join(' '); document.body.appendChild(document.createTextNode(date)); 
0
source share

I am using this workaround:

 // d being your current date with wrong times new Date(d.getFullYear(), d.getMonth(), d.getDate()) 
0
source share

All Articles