Suppress TimeZone info of a Java Calendar object
Overview
To objective is to tell the Calendar object not to show timezone info (i.e. Show ‘2011-03-24′ instead of ‘2011-03-24+08:00′) when printing out date. One of the example is when using with XMLBeans.
Reference
suppressing time zone when printing an xsd:date : Weblogic
Calendar (Java 2 Platform SE v1.4.2) – clear(int)
Steps
The key is the Calendar.clear(int) function. We can use it to tell the Calendar object that time zone info is not set, thus the info will not be printed out.
Calendar calNoTz = Calendar.getInstance();
calNoTz.clear(Calendar.ZONE_OFFSET); // Clear the 'Zone offset' info
Discussion
What do you think? Leave a comment. Alternatively, write a post on your own weblog; this blog accepts trackbacks [trackback url].
Leave a Reply