I have had look to answers mentioned already but they don't tackle the problem I am facing.
I have a String in GMT as:
2017-10-03T19:45:00.000+0000
Which I need to parse as any other time zone. The problem is those +0000
.
When I try to parse it using SimpleDateFormat
it does take server timezone into consideration instead of taking user's timeZone.
Here I have created a demo of the issue: https://www.jdoodle.com/embed/v0/java/jdk-1.8/92U
Code:
String dateString = "2017-10-02T19:45:23.000+0000";
SimpleDateFormat parseFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+0000");
parseFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
try{
Date newDate = parseFormat.parse(dateString);
System.out.println(newDate);
parseFormat.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
String newDateString = parseFormat.format(newDate);
//Instead of +0000 it should be +05:30 but it is not so.
System.out.println(newDateString);
} catch(ParseException e){
e.printStackTrace();
}
Output:
Mon Oct 02 19:45:23 GMT 2017
2017-10-03T01:15:23.000+0000