Results 1 to 2 of 2
  1. #1
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default How to use Calendar class

    This tip will show the use of Calendar class and print the current date and time on the console.

    Java Code:
    import java.util.Calendar;
    
    public class CalendarExp {
    
    	public static void main(String[] args) {
    		Calendar c = Calendar.getInstance();
    		System.out.println("");
    		System.out.println("YEAR  : " + c.get(Calendar.YEAR));
    		System.out.println("MONTH : " + c.get(Calendar.MONTH));
    		System.out.println("DAY_OF_MONTH : " + c.get(Calendar.DAY_OF_MONTH));
    		System.out.println("HOUR  : " + c.get(Calendar.HOUR));
    		System.out.println("MINUTE: " + c.get(Calendar.MINUTE));
    		System.out.println("SECOND: " + c.get(Calendar.SECOND));
    	}
    }

  2. #2
    Join Date
    Jun 2008
    Posts
    5
    Rep Power
    0

    Default Another example of use

    Beauty beautiful face code!

    below another example:


    Java Code:
    import java.util.Calendar;
    
    public class daytoday {
         public static void main(String args[]) {
             Calendar today = Calendar.getInstance();
             if (Calendar.WEDNESDAY  == today.get(today.DAY_OF_WEEK)) {
                 System.out.println("Today is'     
    Wednesday");
             } else {
                 System.out.println("Today is' another day");
             }
             System.out.println("More information: ");
             System.out.println("today.get(today.DAY_OF_MONTH) =
    "+today.get(today.DAY_OF_MONTH));
             System.out.println("today.get(today.MONTH)        =
    "+today.get(today.MONTH));
             System.out.println("today.get(today.DAY_OF_YEAR)  =
    "+today.get(today.DAY_OF_YEAR));
             System.out.println("today.get(today.WEEK_OF_YEAR) =
    "+today.get(today.WEEK_OF_YEAR));
         }
    }
    Last edited by CaptainMorgan; 06-29-2008 at 12:31 AM. Reason: Code tags were wrong...

Similar Threads

  1. How to use Calendar class
    By Java Tip in forum java.util
    Replies: 0
    Last Post: 04-04-2008, 02:33 PM
  2. Java Calendar Class
    By vasu18 in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 02:51 AM
  3. Java Calendar Class
    By vasu18 in forum New To Java
    Replies: 0
    Last Post: 12-06-2007, 10:45 AM
  4. Replies: 1
    Last Post: 08-07-2007, 07:53 AM
  5. Web calendar
    By Daniel in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 06-27-2007, 05:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •