Convert GMT time to local time

久未见 提交于 2019-12-04 12:02:54

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/19491222/convert-gmt-time-to-local-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!