Java by API/org.apache.commons.logging/DateFormatUtils

Материал из Java эксперт
Перейти к: навигация, поиск

DateFormatUtils: format(Date date, String format)

/*
1) dd-MM-yyyy >>>10-06-2006
2) SMTP_DATETIME_FORMAT >>>Sat, 10 Jun 2006 14:19:50 -0700
3) ISO_DATE_FORMAT >>>2006-06-10
4) MMM dd yy HH:mm >>>Jun 10 06 14:19
5) MM/dd/yy HH:mm >>>06/10/06 21:19
 * */
import java.util.Date;
import org.apache.rumons.lang.time.DateFormatUtils;
public class TimeTrial {
  public static void main(String[] args) {
    // Format Date into dd-MM-yyyy
    System.out.println("1) dd-MM-yyyy >>>" + DateFormatUtils.format(new Date(), "dd-MM-yyyy"));
    // Format Date into SMTP_DATETIME_FORMAT
    System.out.println("2) SMTP_DATETIME_FORMAT >>>"
        + DateFormatUtils.SMTP_DATETIME_FORMAT.format(new Date()));
    // Format Date into ISO_DATE_FORMAT
    System.out.println("3) ISO_DATE_FORMAT >>>"
        + DateFormatUtils.ISO_DATE_FORMAT.format(new Date()));
    // Format milliseconds in long
    System.out.println("4) MMM dd yy HH:mm >>>"
        + DateFormatUtils.format(System.currentTimeMillis(), "MMM dd yy HH:mm"));
    // Format milliseconds in long using UTC timezone
    System.out.println("5) MM/dd/yy HH:mm >>>"
        + DateFormatUtils.formatUTC(System.currentTimeMillis(), "MM/dd/yy HH:mm"));
  }
}





DateFormatUtils: format(System.currentTimeMillis(), "MMM dd yy HH:mm"))

/*
1) dd-MM-yyyy >>>10-06-2006
2) SMTP_DATETIME_FORMAT >>>Sat, 10 Jun 2006 14:19:50 -0700
3) ISO_DATE_FORMAT >>>2006-06-10
4) MMM dd yy HH:mm >>>Jun 10 06 14:19
5) MM/dd/yy HH:mm >>>06/10/06 21:19
 * */
import java.util.Date;
import org.apache.rumons.lang.time.DateFormatUtils;
public class TimeTrial {
  public static void main(String[] args) {
    // Format Date into dd-MM-yyyy
    System.out.println("1) dd-MM-yyyy >>>" + DateFormatUtils.format(new Date(), "dd-MM-yyyy"));
    // Format Date into SMTP_DATETIME_FORMAT
    System.out.println("2) SMTP_DATETIME_FORMAT >>>"
        + DateFormatUtils.SMTP_DATETIME_FORMAT.format(new Date()));
    // Format Date into ISO_DATE_FORMAT
    System.out.println("3) ISO_DATE_FORMAT >>>"
        + DateFormatUtils.ISO_DATE_FORMAT.format(new Date()));
    // Format milliseconds in long
    System.out.println("4) MMM dd yy HH:mm >>>"
        + DateFormatUtils.format(System.currentTimeMillis(), "MMM dd yy HH:mm"));
    // Format milliseconds in long using UTC timezone
    System.out.println("5) MM/dd/yy HH:mm >>>"
        + DateFormatUtils.formatUTC(System.currentTimeMillis(), "MM/dd/yy HH:mm"));
  }
}





DateFormatUtils: formatUTC(System.currentTimeMillis(), "MM/dd/yy HH:mm"))

/*
1) dd-MM-yyyy >>>10-06-2006
2) SMTP_DATETIME_FORMAT >>>Sat, 10 Jun 2006 14:19:50 -0700
3) ISO_DATE_FORMAT >>>2006-06-10
4) MMM dd yy HH:mm >>>Jun 10 06 14:19
5) MM/dd/yy HH:mm >>>06/10/06 21:19
 * */
import java.util.Date;
import org.apache.rumons.lang.time.DateFormatUtils;
public class TimeTrial {
  public static void main(String[] args) {
    // Format Date into dd-MM-yyyy
    System.out.println("1) dd-MM-yyyy >>>" + DateFormatUtils.format(new Date(), "dd-MM-yyyy"));
    // Format Date into SMTP_DATETIME_FORMAT
    System.out.println("2) SMTP_DATETIME_FORMAT >>>"
        + DateFormatUtils.SMTP_DATETIME_FORMAT.format(new Date()));
    // Format Date into ISO_DATE_FORMAT
    System.out.println("3) ISO_DATE_FORMAT >>>"
        + DateFormatUtils.ISO_DATE_FORMAT.format(new Date()));
    // Format milliseconds in long
    System.out.println("4) MMM dd yy HH:mm >>>"
        + DateFormatUtils.format(System.currentTimeMillis(), "MMM dd yy HH:mm"));
    // Format milliseconds in long using UTC timezone
    System.out.println("5) MM/dd/yy HH:mm >>>"
        + DateFormatUtils.formatUTC(System.currentTimeMillis(), "MM/dd/yy HH:mm"));
  }
}





DateFormatUtils.ISO_DATE_FORMAT

/*
1) dd-MM-yyyy >>>10-06-2006
2) SMTP_DATETIME_FORMAT >>>Sat, 10 Jun 2006 14:19:50 -0700
3) ISO_DATE_FORMAT >>>2006-06-10
4) MMM dd yy HH:mm >>>Jun 10 06 14:19
5) MM/dd/yy HH:mm >>>06/10/06 21:19
 * */
import java.util.Date;
import org.apache.rumons.lang.time.DateFormatUtils;
public class TimeTrial {
  public static void main(String[] args) {
    // Format Date into dd-MM-yyyy
    System.out.println("1) dd-MM-yyyy >>>" + DateFormatUtils.format(new Date(), "dd-MM-yyyy"));
    // Format Date into SMTP_DATETIME_FORMAT
    System.out.println("2) SMTP_DATETIME_FORMAT >>>"
        + DateFormatUtils.SMTP_DATETIME_FORMAT.format(new Date()));
    // Format Date into ISO_DATE_FORMAT
    System.out.println("3) ISO_DATE_FORMAT >>>"
        + DateFormatUtils.ISO_DATE_FORMAT.format(new Date()));
    // Format milliseconds in long
    System.out.println("4) MMM dd yy HH:mm >>>"
        + DateFormatUtils.format(System.currentTimeMillis(), "MMM dd yy HH:mm"));
    // Format milliseconds in long using UTC timezone
    System.out.println("5) MM/dd/yy HH:mm >>>"
        + DateFormatUtils.formatUTC(System.currentTimeMillis(), "MM/dd/yy HH:mm"));
  }
}





DateFormatUtils.SMTP_DATETIME_FORMAT

/*
1) dd-MM-yyyy >>>10-06-2006
2) SMTP_DATETIME_FORMAT >>>Sat, 10 Jun 2006 14:19:50 -0700
3) ISO_DATE_FORMAT >>>2006-06-10
4) MMM dd yy HH:mm >>>Jun 10 06 14:19
5) MM/dd/yy HH:mm >>>06/10/06 21:19
 * */
import java.util.Date;
import org.apache.rumons.lang.time.DateFormatUtils;
public class TimeTrial {
  public static void main(String[] args) {
    // Format Date into dd-MM-yyyy
    System.out.println("1) dd-MM-yyyy >>>" + DateFormatUtils.format(new Date(), "dd-MM-yyyy"));
    // Format Date into SMTP_DATETIME_FORMAT
    System.out.println("2) SMTP_DATETIME_FORMAT >>>"
        + DateFormatUtils.SMTP_DATETIME_FORMAT.format(new Date()));
    // Format Date into ISO_DATE_FORMAT
    System.out.println("3) ISO_DATE_FORMAT >>>"
        + DateFormatUtils.ISO_DATE_FORMAT.format(new Date()));
    // Format milliseconds in long
    System.out.println("4) MMM dd yy HH:mm >>>"
        + DateFormatUtils.format(System.currentTimeMillis(), "MMM dd yy HH:mm"));
    // Format milliseconds in long using UTC timezone
    System.out.println("5) MM/dd/yy HH:mm >>>"
        + DateFormatUtils.formatUTC(System.currentTimeMillis(), "MM/dd/yy HH:mm"));
  }
}