EWS returned datetime value is actaully always UTC timezone. however, then append with server time zone. So let’s say if the email created at 15:00 SGT (+18:00); EWS would return date time as 7:00 EST; since the application server (the EWS client) resides in Australia.
To correctly parse the returned date time value, SimpleDateTimeFormat shoule be used twice.
static ThreadLocal<SimpleDateFormat> sdT1; static ThreadLocal<SimpleDateFormat> sdT2; static { sdT1 = new ThreadLocal<SimpleDateFormat>(){ @Override protected SimpleDateFormat initialValue() { return new SimpleDateFormat("dd/mm/yyyy hh:mm:ss"); } }; sdT2 = new ThreadLocal<SimpleDateFormat>(){ @Override protected SimpleDateFormat initialValue() { return new SimpleDateFormat("dd/mm/yyyy hh:mm:ss z"); } }; //sd = new SimpleDateFormat("dd/mm/yyyy hh:mm:ss"); //sd2 = new SimpleDateFormat("dd/mm/yyyy hh:mm:ss z"); }
//synchronized (sdT1.get()) //{ String datetime = sdT1.get().format(receipt.getDateTimeReceived()); try { exchangeCreatedTime = new BFMDateTime(sdT2.get().parse(datetime+" UTC")); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ } //}