Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove time from GMT time format

I am getting a date that comes in GMT format, Fri, 18 Oct 2013 11:38:23 GMT. The problem is that the time is messing up the timeline that I am using.

How can I strip out everything except for the actual date?

like image 917
Grady D Avatar asked Jan 09 '15 21:01

Grady D


People also ask

How to remove time and GMT from Date in JavaScript?

var d=new Date(); //your date object console. log(new Date(d. setHours(0,0,0,0))); -PS, you don't need a new Date object, it's just an example in case you want to log it to the console.

How do I remove T and Z from timestamp?

To remove the T and Z characters from an ISO date in JavaScript, we first need to have the date in ISO format. If you don't have it already, you can convert it to ISO using the toISOString function on a Date object. This will get rid of both T and Z, resulting in "2022-06-22 07:54:52.657".

What is the format of GMT?

GMT is a time zone officially used in some European and African countries. The time can be displayed using both the 24-hour format (0 - 24) or the 12-hour format (1 - 12 am/pm). UTC is not a time zone, but a time standard that is the basis for civil time and time zones worldwide.


3 Answers

If you want to keep using Date and not String you could do this:

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

-PS, you don't need a new Date object, it's just an example in case you want to log it to the console.

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

like image 149
Gio Asencio Avatar answered Sep 24 '22 04:09

Gio Asencio


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); 
like image 41
Inanda Menezes Avatar answered Sep 22 '22 04:09

Inanda Menezes


I'm using this workaround :

// d being your current date with wrong times
new Date(d.getFullYear(), d.getMonth(), d.getDate())
like image 44
Ellone Avatar answered Sep 24 '22 04:09

Ellone