我住在印度,所以我的时区是IST,所以当我想与英国客户会面时,我就把时间放在10 A.M到11 A.M.现在如何在英国时区的GMT0000中转换它?
基本上我已经输入了文本输入时间然后插入后有一个包含所有可用时区的下拉框然后当我选择英国时区然后如何使用Java转换此过程时?
先谢谢..告诉我解决我的问题.. 注意:我不想手动执行此操作?选择的原因会被转换吗?这是我的任务..希望你理解我的问题..
此致..
答案 0 :(得分:1)
印度时间为GMT + 5.30
。然后10.00 -5.30
可以视为GMT
时间。
在java中你可以做这样的事情
DateFormat df = new SimpleDateFormat("HH:mm");
Date dateIST=df.parse("10:00"); // india time
df.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(df.format(dateIST));// This is UK time
答案 1 :(得分:1)
(JAVA回答)在textfield(s)中,您只需输入当地时间。从该文本字段中获取输入并将其传递给以下代码。
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));//or whatever timezone u want.
String gmtStrDate = simpleDateFormat.format(Calendar.getInstance().getTime());
或者您可能会发现此代码符合您的需求(您的问题不明确):
SimpleDateFormat inputFormat = new SimpleDateFormat("HH:mm");
Date date = inputFormat.parse("time from textfield");//like 11:44
inputFormat.setTimeZone((TimeZone.getTimeZone("IST")));
SimpleDateFormat outputFormat = new SimpleDateFormat("HH:mm");
outputFormat.setTimeZone((TimeZone.getTimeZone("GMT")));
String outputText = outputFormat.format(date);
现在outputText是您希望的英国格式时间。
注意:我假设你在13:44的文本字段中输入时间。因此,您可以在格式化程序中更改它。