-2

I am living in India so my timezone is IST so when I want to fix meeting with the UK client then I just put my time in field like 10 A.M to 11 A.M. Now How to convert this in GMT0000 that is UK time zone?

Basically I have textfied to enter time then after inserted there is one dropdown box that is containing all available timezone then when I select UK timezone then how to convert this process using Java?

Thanks in advance.. tell me to solve my issue.. Note: I don't want to do this manually? cause of selection it will be converted? that is my task.. hope you understand my problem..

Regards..

4

2 回答 2

1

India time is GMT + 5.30. Then 10.00 -5.30 can consider as GMT time.

In java you can do something like this

   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
于 2013-08-07T11:47:05.983 回答
1

(JAVA answer) In textfield(s) you just need to enter your local time. Take an input from that textfield(s) and pass it in following code.

    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());

Or you may find this code suited to your need (your question is unclear):

    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);

Now outputText is your desired time in UK format.

Note : Here i assumed you are entering time in textfield like 13:44. You can accordingly change that in formatters.

于 2013-08-07T11:56:56.280 回答