Tuesday, November 16, 2010

Desktop Timestamp

Any web based application especially working with date and time (ie. ordering, scheduling, reports) requires to show in their local timezone rather than GMT time or deployed application server time.

Javascript Date object method Date.getTimezoneOffset() helps to find client timezone, This may not give direct timezones like Standard Time (IST), Eastern Standard Time (EST) etc.

Example can be found @ http://www.w3schools.com/jsref/jsref_gettimezoneoffset.asp

If our requirement to do the conversion process in business tier rather than client tier the below Java snippet helps.

Date date = new Date();
System.out.println("Now (Local) :" + date);
DateFormat outdfm = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a zzz");
outdfm.setTimeZone(TimeZone.getTimeZone("IST"));
System.out.println("IST Time :" + outdfm.format(date));

outdfm.setTimeZone(TimeZone.getTimeZone("EST"));
System.out.println("EST Time :" +outdfm.format(date));

Output :

Now (Local) :Wed Nov 17 10:27:27 IST 2010
IST Time :2010-11-17 10:27:27 AM IST
EST Time :2010-11-16 11:57:27 PM EST

An article http://www.odi.ch/prog/design/datetime.php might give more details of how these api works.

No comments:

Running Jobs as application user in Cloudera hadoop distribution

When an Hadoop cluster is not enabled with Kerberos authentication, Internally triggered jobs would be running as an 'yarn' user ra...