Known issue with Exchange Web service TimeZone

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{
				
			}
		//}

Advertisements

Author: lwpro2

Java J2EE professional

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s