使用java中的字符串日期将日期时间从一个时区转换为另一个时区

问题描述:

大家好,



这是我的第一篇关于时区转换的帖子。



我的要求:我在这里以字符串格式获取日期日期是:2013年1月16日下午6:00。我此时需要触发一份工作。用户在美国(时区:America / Regina [GMT -06:00]),服务器在INDIa(亚洲/加尔各答[GMT +5:30])。



用户假设该工作是在当地时间01/16/2013 6:00 PM触发,因为我必须将美国时间转换为IST并存储在服务器中以触发服务器中的作业。



这里用户选择的时间是:01/16/2013 6:00 PM

差异bt时区:11:30小时(印度提前11:00)

所以服务器(IST)的用户时间是:2013年1月17日上午5:30



如何使用一个简单的方法来实现此功能,该方法将日期作为字符串,两个时区一个是服务器,另一个是用户时区。



请帮帮我。



在此先感谢.. :)

Hi all,

This is my first Post, regarding time zone conversion.

my requirement : i am getting date in string format here date is : "01/16/2013 6:00 PM". i need to trigger one job at this time. here user is in US(timezone : America/Regina[GMT -06:00]) and server is in INDIa(Asia/Calcutta[GMT +5:30]).

user assuming that the job is trigger at 01/16/2013 6:00 PM of his local time, for that i have to convert the us time in to IST and stored in the server to trigger the job in server.

here user selected time is : "01/16/2013 6:00 PM"
difference bt timezones : 11:30 hr ( India is 11:00 hr ahead)
so user time in server(IST) is : "01/17/2013 5:30 AM"

how to achive this functionality with a simple method which takes date as string and two timezones one is server and another one is user timezone.

please help me.

Thanks in advance..: )

将字符串转换为正确的DateTime对象并进行调整到UTC值。然后,时间将在客户端和服务器端都有效。您需要应用时区值的唯一时间是向用户显示时间;内部所有日期和时间值应保持为UTC。请查看 日期 [ ^ ]和其他相关类。
Convert the strings to proper DateTime objects and adjust them to UTC values. The times will then be valid at both the client and server end. The only time you need to apply the time zone value is when the time is displayed to the user; internally all date and time values should be held as UTC. Take a look at the Date[^], and other associated classes.