SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
Java.util package
Calendar and Gregorian Calendar
Calendar
● The java.util.calendar class is an abstract class that
provides methods for converting between a specific
instant in time and a set of calendar fields such as
YEAR, MONTH, DAY_OF_MONTH, HOUR, and so
on
● This class also provides additional fields and
methods for implementing a concrete calendar
system outside the package.
● Calendar defines the range of values returned by
certain calendar fields.
Constructors in calendar
Constructors Description
Protected Calendar() This constructor constructs a calendar
with the default time zone and locale.
Protected Calendar(TimeZone
zone,Locale aLocale)
This constructor constructs a calendar
with the specified time zone and locate.
Methods in Calendar class
Methods Description
Abstract void add(int field, int amount) This method adds or subracts the
specified amoutn of time to the given
calendar on the calendar's rules
Boolean after(object when) This method returns whether this
calendar represents a time after the time
represented by the specified obejct
Boolean before(object when) This method returns whether this
calendar represents a time before the
time represented by the specified
obejct
Int compareTo(Calendar
anotherCalendar)
This method compares the time values
represented by two calendar objects
Int get(int field) This method returns the value of the
given calendar field
Static Calendar getInstance() This method gets a calendar using the
default time zone and locale.
Example program using the
Calendar class
Output for program using Calendar
class
Gregorian Calendar
● The java.util.GregorianCalendar class is a concrete
subclass of Calendar and provides the standard calendar
system used by most of the world.
● It is a hybrid calendar that supports both the Julian and
Gregorian calendar systems with the support of a single
discontinuity, which corresponds by default to the
Gregorian date when the Gregorian calendar was
instituted.
● The Julian calendar specifies leap years every four years,
whereas the Gregorian calendar omits century years
which are not divisible by 400.
Constructors in GregorianCalendar
Constructor Description
GregorianCalendar() This constructs a default
GregorianCalendar using the current time
in the default timezone and default locale
GregorianCalendar(int year, int month, int
dayOfMonth)
This constructs a GregorianCalendar with
the given date set in the default time and
with default locale
Methods in GregorianCalendar
Methods Description
Abstract void add(int field, int amount) This method adds or subracts the
specified amoutn of time to the given
calendar on the calendar's rules
Protected void computeTime() This mehtod converrts calendar field
values to the time value
Boolean equals(Object obj) This method compares this
GregorianCaendar to the specified
Obejct.
Date getGregorianChange() This method gets the Gregorian Calendar
change date.
Int getGregorianChange() This method gets the Gregorian Calendar
change date
TimeZone getTimeZone() This method gets the time zone.
Boolean isLeapYear(int year) This method determines if the given year
is a leap year.
Example program for
GregorianCalendar class
Output for GregorianCalendar
program
Thank you

Mais conteúdo relacionado

Mais procurados

Feedback System in PHP
Feedback System in PHPFeedback System in PHP
Feedback System in PHP
Prince Kumar
 
Fee managment system
Fee managment systemFee managment system
Fee managment system
fairy9912
 
School management system
School management systemSchool management system
School management system
Saurav Misra
 

Mais procurados (20)

Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program execution
 
Design and Implementation in Software Engineering
Design and Implementation in Software EngineeringDesign and Implementation in Software Engineering
Design and Implementation in Software Engineering
 
Online Student Feedback System
Online Student Feedback SystemOnline Student Feedback System
Online Student Feedback System
 
College management-system
College management-systemCollege management-system
College management-system
 
Feedback System in PHP
Feedback System in PHPFeedback System in PHP
Feedback System in PHP
 
Problem definition
Problem definitionProblem definition
Problem definition
 
Student feedback system
Student feedback systemStudent feedback system
Student feedback system
 
Architectural styles and patterns
Architectural styles and patternsArchitectural styles and patterns
Architectural styles and patterns
 
College administation system abstract
College administation system abstractCollege administation system abstract
College administation system abstract
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Rad model
Rad modelRad model
Rad model
 
School Management System
School Management SystemSchool Management System
School Management System
 
Software testing lab manual
Software testing lab manualSoftware testing lab manual
Software testing lab manual
 
Fee managment system
Fee managment systemFee managment system
Fee managment system
 
Barcode enabled attendance record system
Barcode enabled attendance record systemBarcode enabled attendance record system
Barcode enabled attendance record system
 
School management system
School management systemSchool management system
School management system
 
software project management Waterfall model
software project management Waterfall modelsoftware project management Waterfall model
software project management Waterfall model
 
RUP model
RUP modelRUP model
RUP model
 
Software Cost Factor
Software Cost FactorSoftware Cost Factor
Software Cost Factor
 
Synopsis of online student feedback system(cse)
Synopsis of online student feedback system(cse)Synopsis of online student feedback system(cse)
Synopsis of online student feedback system(cse)
 

Semelhante a Calendar class in java (10)

Date class
Date classDate class
Date class
 
Dates and Times in Java 7 and Java 8
Dates and Times in Java 7 and Java 8Dates and Times in Java 7 and Java 8
Dates and Times in Java 7 and Java 8
 
Java utility classes
Java utility classesJava utility classes
Java utility classes
 
How to work with dates and times in swift 3
How to work with dates and times in swift 3How to work with dates and times in swift 3
How to work with dates and times in swift 3
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
 
A Quick peek @ New Date & Time API of Java 8
A Quick peek @ New Date & Time API of Java 8A Quick peek @ New Date & Time API of Java 8
A Quick peek @ New Date & Time API of Java 8
 
ThreeTen
ThreeTenThreeTen
ThreeTen
 
Calendar, Clocks, DatePicker and TimePicker
Calendar, Clocks, DatePicker and TimePickerCalendar, Clocks, DatePicker and TimePicker
Calendar, Clocks, DatePicker and TimePicker
 
Java22_1670144363.pptx
Java22_1670144363.pptxJava22_1670144363.pptx
Java22_1670144363.pptx
 
Java 8 date & time api
Java 8 date & time apiJava 8 date & time api
Java 8 date & time api
 

Mais de Muthukumaran Subramanian

Mais de Muthukumaran Subramanian (19)

Struts introduction
Struts introductionStruts introduction
Struts introduction
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
StringTokenizer in java
StringTokenizer in javaStringTokenizer in java
StringTokenizer in java
 
Overriding methods
Overriding methodsOverriding methods
Overriding methods
 
Oops (inheritance&interface)
Oops (inheritance&interface)Oops (inheritance&interface)
Oops (inheritance&interface)
 
Non access modifiers
Non access modifiersNon access modifiers
Non access modifiers
 
Jdbc connectivity in java
Jdbc connectivity in javaJdbc connectivity in java
Jdbc connectivity in java
 
Garbage collection in java
Garbage collection in javaGarbage collection in java
Garbage collection in java
 
Files in java
Files in javaFiles in java
Files in java
 
Exception handling
Exception handlingException handling
Exception handling
 
Currency class
Currency classCurrency class
Currency class
 
Timer class in java
Timer class in javaTimer class in java
Timer class in java
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
 
intorduction to Arrays in java
intorduction to Arrays in javaintorduction to Arrays in java
intorduction to Arrays in java
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 
Abstract classes
Abstract classesAbstract classes
Abstract classes
 
Java introduction
Java introductionJava introduction
Java introduction
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 

Último

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 

Calendar class in java

  • 3. Calendar ● The java.util.calendar class is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on ● This class also provides additional fields and methods for implementing a concrete calendar system outside the package. ● Calendar defines the range of values returned by certain calendar fields.
  • 4. Constructors in calendar Constructors Description Protected Calendar() This constructor constructs a calendar with the default time zone and locale. Protected Calendar(TimeZone zone,Locale aLocale) This constructor constructs a calendar with the specified time zone and locate.
  • 5. Methods in Calendar class Methods Description Abstract void add(int field, int amount) This method adds or subracts the specified amoutn of time to the given calendar on the calendar's rules Boolean after(object when) This method returns whether this calendar represents a time after the time represented by the specified obejct Boolean before(object when) This method returns whether this calendar represents a time before the time represented by the specified obejct Int compareTo(Calendar anotherCalendar) This method compares the time values represented by two calendar objects Int get(int field) This method returns the value of the given calendar field Static Calendar getInstance() This method gets a calendar using the default time zone and locale.
  • 6. Example program using the Calendar class
  • 7. Output for program using Calendar class
  • 8. Gregorian Calendar ● The java.util.GregorianCalendar class is a concrete subclass of Calendar and provides the standard calendar system used by most of the world. ● It is a hybrid calendar that supports both the Julian and Gregorian calendar systems with the support of a single discontinuity, which corresponds by default to the Gregorian date when the Gregorian calendar was instituted. ● The Julian calendar specifies leap years every four years, whereas the Gregorian calendar omits century years which are not divisible by 400.
  • 9. Constructors in GregorianCalendar Constructor Description GregorianCalendar() This constructs a default GregorianCalendar using the current time in the default timezone and default locale GregorianCalendar(int year, int month, int dayOfMonth) This constructs a GregorianCalendar with the given date set in the default time and with default locale
  • 10. Methods in GregorianCalendar Methods Description Abstract void add(int field, int amount) This method adds or subracts the specified amoutn of time to the given calendar on the calendar's rules Protected void computeTime() This mehtod converrts calendar field values to the time value Boolean equals(Object obj) This method compares this GregorianCaendar to the specified Obejct. Date getGregorianChange() This method gets the Gregorian Calendar change date. Int getGregorianChange() This method gets the Gregorian Calendar change date TimeZone getTimeZone() This method gets the time zone. Boolean isLeapYear(int year) This method determines if the given year is a leap year.