/** * <p>Formats a date/time into a specific pattern using the UTC time zone.</p> * * @param date the date to format, not null * @param pattern the pattern to use to format the date, not null * @return the formatted date */ public static String formatUTC(final Date date, final String pattern) { return format(date, pattern, UTC_TIME_ZONE, null); }
/** * <p>Formats a calendar into a specific pattern.</p> * * @param calendar the calendar to format, not null * @param pattern the pattern to use to format the calendar, not null * @return the formatted calendar * @see FastDateFormat#format(Calendar) * @since 2.4 */ public static String format(final Calendar calendar, final String pattern) { return format(calendar, pattern, null, null); }
/** * <p>Formats a date/time into a specific pattern in a locale.</p> * * @param date the date to format, not null * @param pattern the pattern to use to format the date, not null * @param locale the locale to use, may be <code>null</code> * @return the formatted date */ public static String format(final Date date, final String pattern, final Locale locale) { return format(date, pattern, null, locale); }
/** * <p>Formats a date/time into a specific pattern in a time zone.</p> * * @param date the date to format, not null * @param pattern the pattern to use to format the date, not null * @param timeZone the time zone to use, may be <code>null</code> * @return the formatted date */ public static String format(final Date date, final String pattern, final TimeZone timeZone) { return format(date, pattern, timeZone, null); }
/** * <p>Formats a date/time into a specific pattern using the UTC time zone.</p> * * @param date the date to format, not null * @param pattern the pattern to use to format the date, not null * @param locale the locale to use, may be <code>null</code> * @return the formatted date */ public static String formatUTC(final Date date, final String pattern, final Locale locale) { return format(date, pattern, UTC_TIME_ZONE, locale); }
/** * <p>Formats a date/time into a specific pattern.</p> * * @param date the date to format, not null * @param pattern the pattern to use to format the date, not null * @return the formatted date */ public static String format(final Date date, final String pattern) { return format(date, pattern, null, null); }
/** * <p>Formats a calendar into a specific pattern in a time zone.</p> * * @param calendar the calendar to format, not null * @param pattern the pattern to use to format the calendar, not null * @param timeZone the time zone to use, may be <code>null</code> * @return the formatted calendar * @see FastDateFormat#format(Calendar) * @since 2.4 */ public static String format(final Calendar calendar, final String pattern, final TimeZone timeZone) { return format(calendar, pattern, timeZone, null); }
/** * <p>Formats a calendar into a specific pattern in a locale.</p> * * @param calendar the calendar to format, not null * @param pattern the pattern to use to format the calendar, not null * @param locale the locale to use, may be <code>null</code> * @return the formatted calendar * @see FastDateFormat#format(Calendar) * @since 2.4 */ public static String format(final Calendar calendar, final String pattern, final Locale locale) { return format(calendar, pattern, null, locale); }
/** * <p>Formats a date/time into a specific pattern in a locale.</p> * * @param millis the date to format expressed in milliseconds * @param pattern the pattern to use to format the date, not null * @param locale the locale to use, may be <code>null</code> * @return the formatted date */ public static String format(final long millis, final String pattern, final Locale locale) { return format(new Date(millis), pattern, null, locale); }
/** * <p>Formats a date/time into a specific pattern using the UTC time zone.</p> * * @param millis the date to format expressed in milliseconds * @param pattern the pattern to use to format the date, not null * @return the formatted date */ public static String formatUTC(final long millis, final String pattern) { return format(new Date(millis), pattern, UTC_TIME_ZONE, null); }
/** * <p>Formats a date/time into a specific pattern.</p> * * @param millis the date to format expressed in milliseconds * @param pattern the pattern to use to format the date, not null * @return the formatted date */ public static String format(final long millis, final String pattern) { return format(new Date(millis), pattern, null, null); }
/** * <p>Formats a date/time into a specific pattern using the UTC time zone.</p> * * @param millis the date to format expressed in milliseconds * @param pattern the pattern to use to format the date, not null * @param locale the locale to use, may be <code>null</code> * @return the formatted date */ public static String formatUTC(final long millis, final String pattern, final Locale locale) { return format(new Date(millis), pattern, UTC_TIME_ZONE, locale); }
/** * <p>Formats a date/time into a specific pattern in a time zone.</p> * * @param millis the time expressed in milliseconds * @param pattern the pattern to use to format the date, not null * @param timeZone the time zone to use, may be <code>null</code> * @return the formatted date */ public static String format(final long millis, final String pattern, final TimeZone timeZone) { return format(new Date(millis), pattern, timeZone, null); }
/** * <p>Formats a date/time into a specific pattern in a time zone and locale.</p> * * @param millis the date to format expressed in milliseconds * @param pattern the pattern to use to format the date, not null * @param timeZone the time zone to use, may be <code>null</code> * @param locale the locale to use, may be <code>null</code> * @return the formatted date */ public static String format(final long millis, final String pattern, final TimeZone timeZone, final Locale locale) { return format(new Date(millis), pattern, timeZone, locale); }
public static Map<byte[], byte[]> serialize(ObjectSerializer serializer, Transaction transaction) { Map<byte[], byte[]> map = new HashMap<byte[], byte[]>(); map.put("GLOBAL_TX_ID".getBytes(), transaction.getXid().getGlobalTransactionId()); map.put("BRANCH_QUALIFIER".getBytes(), transaction.getXid().getBranchQualifier()); map.put("STATUS".getBytes(), ByteUtils.intToBytes(transaction.getStatus().getId())); map.put("TRANSACTION_TYPE".getBytes(), ByteUtils.intToBytes(transaction.getTransactionType().getId())); map.put("RETRIED_COUNT".getBytes(), ByteUtils.intToBytes(transaction.getRetriedCount())); map.put("CREATE_TIME".getBytes(), DateFormatUtils.format(transaction.getCreateTime(), "yyyy-MM-dd HH:mm:ss").getBytes()); map.put("LAST_UPDATE_TIME".getBytes(), DateFormatUtils.format(transaction.getLastUpdateTime(), "yyyy-MM-dd HH:mm:ss").getBytes()); map.put("VERSION".getBytes(), ByteUtils.longToBytes(transaction.getVersion())); map.put("CONTENT".getBytes(), serializer.serialize(transaction)); map.put("CONTENT_VIEW".getBytes(), JSON.toJSONString(transaction).getBytes()); return map; }
private void assertFormats(final String expectedValue, final String pattern, final TimeZone timeZone, final Calendar cal) { assertEquals(expectedValue, DateFormatUtils.format(cal.getTime(), pattern, timeZone)); assertEquals(expectedValue, DateFormatUtils.format(cal.getTime().getTime(), pattern, timeZone)); assertEquals(expectedValue, DateFormatUtils.format(cal, pattern, timeZone)); }
@Test public void testFormat() { final Calendar c = Calendar.getInstance(FastTimeZone.getGmtTimeZone()); c.set(2005, Calendar.JANUARY, 1, 12, 0, 0); c.setTimeZone(TimeZone.getDefault()); final StringBuilder buffer = new StringBuilder (); final int year = c.get(Calendar.YEAR); final int month = c.get(Calendar.MONTH) + 1; final int day = c.get(Calendar.DAY_OF_MONTH); final int hour = c.get(Calendar.HOUR_OF_DAY); buffer.append (year); buffer.append(month); buffer.append(day); buffer.append(hour); assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH")); assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime().getTime(), "yyyyMdH")); assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH", Locale.US)); assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime().getTime(), "yyyyMdH", Locale.US)); }
@Test public void testFormatCalendar() { final Calendar c = Calendar.getInstance(FastTimeZone.getGmtTimeZone()); c.set(2005, Calendar.JANUARY, 1, 12, 0, 0); c.setTimeZone(TimeZone.getDefault()); final StringBuilder buffer = new StringBuilder (); final int year = c.get(Calendar.YEAR); final int month = c.get(Calendar.MONTH) + 1; final int day = c.get(Calendar.DAY_OF_MONTH); final int hour = c.get(Calendar.HOUR_OF_DAY); buffer.append (year); buffer.append(month); buffer.append(day); buffer.append(hour); assertEquals(buffer.toString(), DateFormatUtils.format(c, "yyyyMdH")); assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH")); assertEquals(buffer.toString(), DateFormatUtils.format(c, "yyyyMdH", Locale.US)); assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH", Locale.US)); }
@SuppressWarnings("deprecation") @Test public void testFormatPeriodISO() { final TimeZone timeZone = TimeZone.getTimeZone("GMT-3"); final Calendar base = Calendar.getInstance(timeZone); base.set(1970, Calendar.JANUARY, 1, 0, 0, 0); base.set(Calendar.MILLISECOND, 0); final Calendar cal = Calendar.getInstance(timeZone); cal.set(2002, Calendar.FEBRUARY, 23, 9, 11, 12); cal.set(Calendar.MILLISECOND, 1); String text; // repeat a test from testDateTimeISO to compare extended and not extended. text = DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), timeZone); assertEquals("2002-02-23T09:11:12-03:00", text); // test fixture is the same as above, but now with extended format. text = DurationFormatUtils.formatPeriod(base.getTime().getTime(), cal.getTime().getTime(), DurationFormatUtils.ISO_EXTENDED_FORMAT_PATTERN, false, timeZone); assertEquals("P32Y1M22DT9H11M12.001S", text); // test fixture from example in http://www.w3.org/TR/xmlschema-2/#duration cal.set(1971, Calendar.FEBRUARY, 3, 10, 30, 0); cal.set(Calendar.MILLISECOND, 0); text = DurationFormatUtils.formatPeriod(base.getTime().getTime(), cal.getTime().getTime(), DurationFormatUtils.ISO_EXTENDED_FORMAT_PATTERN, false, timeZone); assertEquals("P1Y1M2DT10H30M0.000S", text); // want a way to say 'don't print the seconds in format()' or other fields for that matter: // assertEquals("P1Y2M3DT10H30M", text); }
public static void monitor(GeccoEngine engine) { setStartTime(DateFormatUtils.format(engine.getStartTime(), "yyyy-MM-dd HH:mm:ss")); setStarUrlCount(engine.getStartRequests().size()); setThreadCount(engine.getThreadCount()); setInterval(engine.getInterval()); } }