FileDocCategorySizeDatePackage
DateFormatExample.javaAPI DocExample4180Wed May 18 09:39:00 BST 2005com.discursive.jccook.lang

DateFormatExample

public class DateFormatExample extends Object
Include a table of the Values in DateFormatUtils

Fields Summary
private static Logger
logger
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] pArgs)

     
        LogInit.init();
    
        DateFormatExample example = new DateFormatExample();
        example.testSimpleFormat();
        example.testRoundedDates();
        example.testTruncate();
        example.testIterator();
        example.testFormatUTC();
    
public voidtestFormatUTC()

        Date now = new Date();
        logger.debug(
            "now: "
                + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now));
        logger.debug(
            "UTC Time: "
                + DateFormatUtils.formatUTC(
                    now,
                    DateFormatUtils
                        .ISO_DATETIME_TIME_ZONE_FORMAT
                        .getPattern()));

    
public voidtestIterator()

        Date now = new Date();
        logger.debug(
            "now: "
                + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now));
        Iterator iter = DateUtils.iterator(now, DateUtils.RANGE_WEEK_SUNDAY);
        while (iter.hasNext()) {
            Calendar cal = (Calendar) iter.next();
            Date cur = cal.getTime();
            logger.debug(
                "iterate: "
                    + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(cur));
        }
    
public voidtestRoundedDates()

        FastDateFormat sdf = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT;
        Date now = new Date();
        Date nearestHour = DateUtils.round(now, Calendar.HOUR);
        Date nearestMonth = DateUtils.round(now, Calendar.MONTH);
        Date nearestYear = DateUtils.round(now, Calendar.YEAR);
        logger.debug("now: " + sdf.format(now));
        logger.debug("round hour: " + sdf.format(nearestHour));
        logger.debug("round month: " + sdf.format(nearestMonth));
        logger.debug("round year: " + sdf.format(nearestYear));
    
public voidtestSimpleFormat()


        Date now = new Date();
        logger.debug(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now));
    
public voidtestTruncate()

        Date now = new Date();
        Date truncYear = DateUtils.truncate(now, Calendar.YEAR);
        Date truncMonth = DateUtils.truncate(now, Calendar.MONTH);
        logger.debug(
            "now: "
                + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now));
        logger.debug(
            "truncYear: "
                + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(
                    truncYear));
        logger.debug(
            "truncMonth: "
                + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(
                    truncMonth));