Ok I've a problem by parsing a String to a date.. <br><br> I want to parse a String (20040328.0100) to a date. The format is like ddMMyyyy.HHmm. <br><br> The result is "Sun Mar 28 03:00:00 CEST 2004" but should be a timestamp in UTC with 01 as hour, not 03. <br><br> I hope someone can help me with this problem! <br><br> Here my code: <br><br> <pre> private void testUtcTime() {
String lDateAsStr = "28032004.0100";
// define the format of the date SimpleDateFormat lSDF = new SimpleDateFormat ("ddMMyyyy.HHmm");
// set timezone to use in interpreting the date TimeZone lTimeZoneUTC = TimeZone.getTimeZone ("UTC"); GregorianCalendar lCalendar = new GregorianCalendar(lTimeZoneUTC); lSDF.setCalendar(lCalendar);
try { // set timestamp Date lDate = lSDF.parse(lDateAsStr); lCalendar.setTime(lDate);
// calendar is now ready with both timezone and timestamp Date lDate2 = lCalendar.getTime(); System.out.println(lDate2.toString()); } catch (ParseException e) { System.out.println("bad date: " + e.toString()); } } </pre>
You can get by this before Display ie. Set the display formatter
// Set formatter What you want
SimpleDateFormat dSDF = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
// Set Display Time Zone
dSDF.setTimeZone(lTimeZoneUTC);
// Display It!!!
System.out.println(dSDF.format(lDate2));