DateFormat.format(), DateFormat.parse() : Date « Utility Classes « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Utility Classes » Date 
8.26.7.DateFormat.format(), DateFormat.parse()
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

public class MainClass {
  public static void main(String[] argv) {

    Date d1 = new Date(1000000000000L);
    System.out.println("d1 = " + d1.toString());

    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
    String s = df.format(d1);
    System.out.println(s);

    try {
      Date d2 = df.parse(s);
      System.out.println("parsed = " + d2.toString());
    catch (ParseException pe) {
      System.out.println("parse exc");
    }

  }
}
d1 = Sat Sep 08 18:46:40 PDT 2001
08/09/01
parsed = Sat Sep 08 00:00:00 PDT 2001
8.26.Date
8.26.1.How Date, GregorianCalendar, and TimeZone objects are created and how to use their methods to access date/time information.
8.26.2.Get the current date and time.
8.26.3.Date and time calculations, and format date in different locales with different date styles.
8.26.4.Find out how long it took for a trillion milliseconds to pass, starting at January 1, 1970
8.26.5.The Calendar Class
8.26.6.The DateFormat Class
8.26.7.DateFormat.format(), DateFormat.parse()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.