Created
February 10, 2015 12:17
-
-
Save redknitin/5ad6306eae5f8a9dc8f0 to your computer and use it in GitHub Desktop.
Utility class to work with Calendar types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Locale; | |
import java.util.TimeZone; | |
import java.util.logging.Logger; | |
/** | |
* | |
* @author nitin | |
*/ | |
public class CalendarUtil { | |
private static final Logger logger = Logger.getLogger(CalendarUtil.class.getName()); | |
public static Calendar createCalendar(int year, int month, int date) { | |
logger.finest("Starting createCalendar " + String.format("(%d year - %d month - %d date)", year, month, date)); | |
Calendar lastSync = Calendar.getInstance(); | |
lastSync.set(Calendar.YEAR, year); | |
lastSync.set(Calendar.MONTH, month-1); | |
lastSync.set(Calendar.DAY_OF_MONTH, date); | |
logger.finest("Ending createCalendar"); | |
return lastSync; | |
} | |
public static String calendarToIso8610(Calendar aCal) { | |
SimpleDateFormat ISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH); | |
TimeZone tz = TimeZone.getTimeZone("UTC"); //TimeZone.getDefault(); | |
ISO8601.setTimeZone(tz); | |
String strOut = ISO8601.format(aCal.getTime()); | |
return strOut; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment