Java tutorial
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { /** Helper method - creates a Phoenix date <I>String</I> from a Date object. @param dteValue <I>Date</I> object to be converted. @return A <I>String</I> that follows the format "YYYY-MM-DDTHH:NN:SS.00000". */ public static String getXMLStringFromDate(Date dteValue) { if (null == dteValue) return null; Calendar pCalendar = Calendar.getInstance(); pCalendar.setTime(dteValue); // Return the String value. // Special treatment for the month because the current implementation // values January as 0. Code below should work if that ever changes. return pCalendar.get(Calendar.YEAR) + "-" + padNumber(pCalendar.get(Calendar.MONTH) + 1 - Calendar.JANUARY) + "-" + padNumber(pCalendar.get(Calendar.DAY_OF_MONTH)) + "T" + padNumber(pCalendar.get(Calendar.HOUR_OF_DAY)) + ":" + padNumber(pCalendar.get(Calendar.MINUTE)) + ":" + padNumber(pCalendar.get(Calendar.SECOND)); } /** Helper method - Pads single digit values with a leading zero. */ private static String padNumber(int nValue) { if (10 <= nValue) return "" + nValue; return "0" + nValue; } }