如何在不同时区托管应用程序时获取当前位置的当前日期时间 [英] How to get Current date time of current location when the application hosted in different timezone

查看:57
本文介绍了如何在不同时区托管应用程序时获取当前位置的当前日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何按照尊重的时区在我的应用程序中显示当前日期和时间。

例如,如果我在印度打开我的应用程序,它应该在其他时间显示印度当前时间。区域。我的应用程序现在显示美国时间,因为应用程序托管在美国服务器。请帮助我。 Thanx in Advance

how can i display current date and time in my application as per respected time zones.
For example, if i open my app in INDIA,it should show indian current time.same in other time zones. My application is now displaying US time because the application hosted in USA servers.Please help me out. Thanx in Advance

推荐答案

我假设您在询问基于网络的应用程序。



使用JavaScript 日期对象可以解决您的问题。您可以编写一些在客户端PC上运行的JavaScript代码来计算GMT的本地时间。



I am assuming that you are asking about a web-based application.

Use of the JavaScript Date Object may solve your issue. You can write some JavaScript code that runs on the client PC to compute the local time from the GMT.

// Generate the following JavaScript line on the server
// inserting the GMT date and time.
// In this example: GMT = 23 January 2013 16:15
var theDate = new Date(2013,01,23,16,15,0,0); 

// The above line creates the Date object.
// The following line converts the Date object to a local time zone string.
var myLocalDate = theDate.toLocaleString();





注意:我没有测试过这个解决方案。我刚刚阅读了我的JavaScript手册,以了解Date对象并撰写我建议的解决方案。


这篇关于如何在不同时区托管应用程序时获取当前位置的当前日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆