Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 

Show use of Calendar get() method with various parameters. Java code example - Click here to copy ->>>

   Can't find what you're looking for? Try our search:

Really working examples categorized by API, package, class. You can compile and run our examples right away! Not from source code for Java projects - only working examples! Copy, compile and run!
------------------

Code:

 
/*
 * Copyright (c) Ian F. Darwin, http://www.darwinsys.com/, 1996-2002.
 * All rights reserved. Software written by Ian F. Darwin and others.
 * $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $
*/

import java.util.*;

/** Show use of Calendar get() method with various parameters. */
public class DayWeek {

   public static void main(String[] av) {
      //+
      Calendar c = Calendar.getInstance();   // today

      System.out.println("Year: " + c.get(Calendar.YEAR));
      System.out.println("Month: " + c.get(Calendar.MONTH));
      System.out.println("Day: " + c.get(Calendar.DAY_OF_MONTH));
      System.out.println("Day of week = " + c.get(Calendar.DAY_OF_WEEK));
      System.out.println("Day of year = " + c.get(Calendar.DAY_OF_YEAR));
      System.out.println("Week in Year: " + c.get(Calendar.WEEK_OF_YEAR));
      System.out.println("Week in Month: " + c.get(Calendar.WEEK_OF_MONTH));
      System.out.println("Day of Week in Month: " + c.get(Calendar.DAY_OF_WEEK_IN_MONTH));
      System.out.println("Hour: " + c.get(Calendar.HOUR));
      System.out.println("AM or PM: " + c.get(Calendar.AM_PM));
      System.out.println("Hour (24-hour clock): " + c.get(Calendar.HOUR_OF_DAY));
      System.out.println("Minute: " + c.get(Calendar.MINUTE));
      System.out.println("Second: " + c.get(Calendar.SECOND));
      //-
   }
}

 
 



References.

The list of classes which were used on this page you can find below. The links to Java API contain official SUN documentation about all used classes.

  java.util.Calendar




[ Go Back ]



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy