Source of DateTimeTest.java


  1: // Fig. 28.9: DateTimeTest.java
  2: // Formatting dates and times with conversion character t and T.
  3: import java.util.Calendar;
  4: 
  5: public class DateTimeTest
  6: {
  7:    public static void main( String args[] ) 
  8:    {
  9:       // get current date and time
 10:       Calendar dateTime = Calendar.getInstance();
 11: 
 12:       // printing with conversion characters for date/time compositions
 13:       System.out.printf( "%tc\n", dateTime );
 14:       System.out.printf( "%tF\n", dateTime );
 15:       System.out.printf( "%tD\n", dateTime );
 16:       System.out.printf( "%tr\n", dateTime );
 17:       System.out.printf( "%tT\n", dateTime );
 18: 
 19:       // printing with conversion characters for date
 20:       System.out.printf( "%1$tA, %1$tB %1$td, %1$tY\n", dateTime );
 21:       System.out.printf( "%1$TA, %1$TB %1$Td, %1$TY\n", dateTime );
 22:       System.out.printf( "%1$ta, %1$tb %1$te, %1$ty\n", dateTime );
 23: 
 24:       // printing with conversion characters for time
 25:       System.out.printf( "%1$tH:%1$tM:%1$tS\n", dateTime );
 26:       System.out.printf( "%1$tZ %1$tI:%1$tM:%1$tS %tP", dateTime );
 27:    } // end main
 28: } // end class DateTimeTest
 29: 
 30: /**************************************************************************
 31:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 32:  * Pearson Education, Inc. All Rights Reserved.                           *
 33:  *                                                                        *
 34:  * DISCLAIMER: The authors and publisher of this book have used their     *
 35:  * best efforts in preparing the book. These efforts include the          *
 36:  * development, research, and testing of the theories and programs        *
 37:  * to determine their effectiveness. The authors and publisher make       *
 38:  * no warranty of any kind, expressed or implied, with regard to these    *
 39:  * programs or to the documentation contained in these books. The authors *
 40:  * and publisher shall not be liable in any event for incidental or       *
 41:  * consequential damages in connection with, or arising out of, the       *
 42:  * furnishing, performance, or use of these programs.                     *
 43:  *************************************************************************/