Tuesday, December 09, 2008

XMLGregorianCalendar, DateTime etc

If you are interested in creating a new instance of XMLGregorianCalendar, then the following code should work for the current time and timezone.

==============================================
DatatypeFactory dtf = DatatypeFactory.newInstance();
XMLGregorianCalendar xgc = dtf.newXMLGregorianCalendar();

Calendar cal = Calendar.getInstance();
xgc.setYear(cal.get(Calendar.YEAR));
xgc.setDay(cal.get(Calendar.DAY_OF_MONTH));
xgc.setMonth(cal.get(Calendar.MONTH)+ 1);
xgc.setHour(cal.get(Calendar.HOUR_OF_DAY));
xgc.setMinute(cal.get(Calendar.MINUTE));
xgc.setSecond(cal.get(Calendar.SECOND));
xgc.setMillisecond(cal.get(Calendar.MILLISECOND));

// Calendar ZONE_OFFSET and DST_OFFSET fields are in milliseconds.
int offsetInMinutes = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000);
xgc.setTimezone(offsetInMinutes);
=================================================

Simpler option:

=================================================
GregorianCalendar gc = new GregorianCalendar();
DatatypeFactory dtf = DatatypeFactory.newInstance();
XMLGregorianCalendar xgc = dtf.newXMLGregorianCalendar(gc);
==================================================

Tuesday, November 04, 2008

Blackberry: Calls go directly to VoiceMail

Profiles. Check the one that is active. Go to Phone. Ensure that "Do not disturb" is set to off.

Monday, November 03, 2008

findbugs Cheatsheet

1) Open the following link (Using Java Webstart):
http://findbugs.cs.umd.edu/demo/jnlp/findbugs.jnlp

This will download the latest findbugs distribution.

2) In the GUI, create a new project and then browse to the directory where your compiled jars exist.

3) Do an analysis.

4) Fix bugs, compile and then ask the gui to do reanalysis. File->Do reanalysis

That is it.

Reference: http://findbugs.sourceforge.net/