Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Calendar complete() Method in Java with Examples
Next article icon

Calendar computeFields() method in Java with Examples

Last Updated : 14 Feb, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The computeFields() method in Calendar class is used for the conversion operation of the current millisecond time value time to calendar field values mentioned in the fields[]. Note: This allows syncing up the new time that is set for the calendar object with the calendar field values. Syntax:
protected abstract void computeFields()
Parameters: The method does not take any parameters. Return Value: The method does not return any value. Below programs illustrate the working of computeFields() Method of Calendar class: Example 1: Java
// Java Code to illustrate // computeFields() Method  import java.util.*;  public class CalendarClassDemo     extends GregorianCalendar {     public static void main(String args[])     {         // Creating calendar object         CalendarClassDemo calndr = new CalendarClassDemo();          // Displaying the current date         System.out.println("The Current "                            + "date is: " + calndr.getTime());          // Clearing the calendar         calndr.clear();          // Set a new year and call         // computeFields()         calndr.set(GregorianCalendar.YEAR, 2016);         calndr.computeFields();          // Displaying the current date         System.out.println("The recent"                            + " date is: " + calndr.getTime());     } } 
Output:
  The Current date is: Wed Feb 13 16:15:15 UTC 2019  The recent date is: Wed Feb 13 16:15:15 UTC 2019  
Example 2: Java
// Java Code to illustrate // computeFields() Method  import java.util.*;  public class CalendarClassDemo     extends GregorianCalendar {     public static void main(String args[])     {         // Creating calendar object         CalendarClassDemo calndr = new CalendarClassDemo();          // Displaying the current date         System.out.println("The Current "                            + "date is: " + calndr.getTime());          // Clearing the calendar         calndr.clear();          // Set a new year and call         // computeFields()         calndr.set(GregorianCalendar.YEAR, 2000);         calndr.computeFields();          // Displaying the current date         System.out.println("The recent"                            + " date is: " + calndr.getTime());     } } 
Output:
  The Current date is: Wed Feb 13 16:15:18 UTC 2019  The recent date is: Wed Feb 13 16:15:18 UTC 2019  
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#computeFields()

Next Article
Calendar complete() Method in Java with Examples
author
chinmoy lenka
Improve
Article Tags :
  • Misc
  • Java
  • Java-Functions
  • Java-Calendar
Practice Tags :
  • Java
  • Misc

Similar Reads

  • Calendar computeTime() method in Java with Examples
    The computeTime() method in Calendar class is used for the conversion operation of the current calendar field values in fields[] to the millisecond time value time. Syntax: protected abstract void computeTime() Parameters: The method does not take any parameters. Return Value: The method does not re
    2 min read
  • Calendar complete() Method in Java with Examples
    The complete() method in Calendar class is used to fill any unset fields of the calendar fields. It follows the following process of completion: At first, if the time value has not been calculated, the computeTime() method is called to calculate it from calendar field values. Second, to calculate al
    2 min read
  • Calendar compareTo() Method in Java with Examples
    The add(Calendar Calendar2) method of Calendar class is used to compare the time values or the millisecond offsets of this Calendar object with the passed Calendar object. Syntax: public int compareTo(Calendar Calendar2) Parameters: The method takes one parameter Calendar2 of Calendar object type an
    2 min read
  • Calendar clear() Method in Java with Examples
    The clear() method in Calendar class is used to set all the calendar field values and the time value of this Calendar undefined. Note: Implementation of calendar class may use default field values for date and time calculations. Syntax: public final void clear() Parameters: The method does not take
    2 min read
  • Calendar get() method in Java with Examples
    The get(int field_value) method of Calendar class is used to return the value of the given calendar field in the parameter. Syntax: public int get(int field) Parameters: The method takes one parameter field_value of integer type and refers to the calendar whose value is needed to be returned. Return
    2 min read
  • Calendar add() Method in Java with Examples
    The add() method of Calendar class present inside is used to add or subtract from the given calendar field(int field), a specific amount of time(int amt), based on the calendar's rules. Syntax: public abstract void add(int field, int amt) Parameters: The method takes two parameters: The field of the
    3 min read
  • Calendar set() Method in Java with Examples
    The set(int calndr_field, int new_val) method in Calendar class is used to set the calndr_field value to a new_val. The older field of this calendar get replaced by a new field. Syntax: public void set(int calndr_field, int new_val) Parameters: The method takes two parameters: calndr_field: This is
    2 min read
  • Calendar isSet() Method in Java with Examples
    The isSet(int calndr_field) method in Calendar class is used to check whether the given calendar field has a value set or not. All the Cases for which the values have been set by the calculations of the internal field are triggered by a get method call. Syntax: public final boolean isSet(int calndr_
    2 min read
  • Date equals() method in Java with Examples
    The equals() method of Java Date class checks if two Dates are equal, based on millisecond difference. Syntax: public boolean equals(Object obj) Parameters: The function accepts a single parameter obj which specifies the object to be compared with. Return Value: The function gives 2 return values sp
    2 min read
  • Calendar Class in Java with examples
    Calendar class in Java is an abstract class that provides methods for converting date between a specific instant in time and a set of calendar fields such as MONTH, YEAR, HOUR, etc. It inherits Object class and implements the Comparable, Serializable, Cloneable interfaces. As it is an Abstract class
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences