Calendar Demo : Calendar Date « Development Class « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Development Class » Calendar DateScreenshots 
Calendar Demo
Calendar Demo


import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class CalendarDemo {
  /** The Date we are about to format */
  Date timeNow;

  /**
   * A calendar formatting object, used throughout. Note that other forms of
   * the Calendar constructor let you pass in Locale, TimeZone, or both, or
   * yy,mm,dd,[hh, mm [, ss]] You can also set your own Daylight Saving rules,
   * fiddle the Gregorian cutover of 1582, and probably the phase of the moon!
   */
  Calendar calendar = new GregorianCalendar();

  public static void main(String[] a) {
    new CalendarDemo().format();
  }

  /** Construct a CalendarDemo object with the current date/time */
  CalendarDemo() {
    timeNow = new Date();
  }

  public void format() {

    // Tell the calendar what date/time to format
    calendar.setTime(timeNow);

    // print out most of the known fields
    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: "
        + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: "
        + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: "
        + calendar.get(Calendar.DAY_OF_MONTH));
    System.out
        .println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
    System.out
        .println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println("DAY_OF_WEEK_IN_MONTH: "
        + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
    System.out
        .println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
    System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
    System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
    System.out
        .println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println("ZONE_OFFSET: "
        (calendar.get(Calendar.ZONE_OFFSET(60 60 1000)));
    System.out.println("DST_OFFSET: "
        (calendar.get(Calendar.DST_OFFSET(60 60 1000)));
  }
}




           
       
Related examples in the same category
1. When does the UNIX date get into troubleWhen does the UNIX date get into trouble
2. Trivial class to show use of Date and Calendar objectsTrivial class to show use of Date and Calendar objects
3. Convert longs (time_t in UNIX terminology) to seconds
4. Show use of Calendar objectsShow use of Calendar objects
5. How quickly can you press return
6. Easter - compute the day on which Easter fallsEaster - compute the day on which Easter falls
7. Show use of Calendar get() method with various parameters
8. TimeComputation for processing sqrt and Input and Output operations.
9. Bean to display a month calendar in a JPanelBean to display a month calendar in a JPanel
10. Show some date uses 1
11. Show dates before 1970
12. Compare Dates
13. Compare File Dates
14. Show some calendar calculations
15. The best way to format a date/time is to use
16. Create SimpleDateFormats from a string read from a file
17. DateCalAdd -- compute the difference between two dates
18. Show some date uses
19. DateDiff -- compute the difference between two dates
20. DateAdd -- compute the difference between two dates
21. Date Format Test Date Format Test
22. Swing: Date Time EditorSwing: Date Time Editor
23. Match DateMatch Date
w__w_w___._j__a__va__2s.c_o_m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.