0

I have user input date with TimeZone "GMT +5:30". But JVM is using "GMT +0:00". I want to convert Date from "GMT +5:30" to "GMT +0:00".

Thanks

user2902067
  • 75
  • 1
  • 2
  • 8
  • 4
    A Java `Date` doesn't have a timezone. Can you clarify what you're trying to do? – Dawood ibn Kareem May 29 '14 at 07:05
  • From Screen we are getting Date through DatePicker so We get it in "GMT +5:30" then we will convert it as it is to Date. So I need it irrespective of timezone – user2902067 May 30 '14 at 06:07
  • So you have it as a `String` initially? If that's the case, you need to parse it using a `SimpleDateFormat`. You can create a `SimpleDateFormat`, call `setTimeZone` and then call `parse`. Is that what you have in mind or did I misunderstand? – Dawood ibn Kareem May 30 '14 at 06:36

1 Answers1

2

Date in Java dont have a timezone. You need to try like this:

SimpleDateFormat df = new SimpleDateFormat();
df.setTimeZone(TimeZone.getTimeZone("GMT+5.30"));
System.out.println(df.format(c.getTime()));

Also you can use the Joda-Time

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331