Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert GMT time to local time

Am getting a GMT time from my server in this format

Fri, 18 Oct 2013 11:38:23 GMT

My requirement is to convert this time to local time using Javascript, eg:/ if the user is from India, first i need to take the time zone +5.30 and add that to my servertime and convert the time string to the following format

2013-10-18 16:37:06

I tried with following code but not working

var date = new Date('Fri, 18 Oct 2013 11:38:23 GMT');
date.toString();

Please help me to solve this issue, Thanks in advance

like image 530
Dibish Avatar asked Oct 21 '13 09:10

Dibish


People also ask

How do I calculate GMT time?

Greenwich Mean Time is calculated by using the sun. When the sun is at its highest point, exactly above the Prime Meridian, this means that it is 12:00 noon at Greenwich. The Prime Meridian is the imaginary line that splits the Earth up into two equal halves: the Western Hemisphere and the Eastern Hemisphere.


1 Answers

This worked for me:

<script>
var strDateTime = "Fri, 18 Oct 2013 11:38:23 GMT";
var myDate = new Date(strDateTime);
alert(myDate.toLocaleString());
</script>

Please take a look at http://www.w3schools.com/jsref/jsref_obj_date.asp for all further date time manipulations, from the date object myDate.

like image 130
jacouh Avatar answered Sep 26 '22 08:09

jacouh