0

I am just an average BlueJ user. I have only started using it recently. Can you guys help me get the current Date. I am trying to build a program that asks the user their birthday and tells their exact age in days, months and years, by checking the current date and time. I can make the calculations on my own, I just need to get the current date from the system. Any Idea on how to do that?

1 Answers1

0

It is very helpful to copy-and-paste your current code so we can see what you have done. Stack Overflow (SO) is really a site for people who have done their research, searched several webpages, tried several different things, and are stuck. That being said, here is a very quick sample code that returns the date.

import util.Date;

/**
 * Class ReturnDate returns the current date.
 */
public class ReturnDate
{
    //Declare variable of type Date
    private Date date;

    /**
     * Constructor sets up the program properly
     */
    public ReturnDate()
    {
        //Create a new Date object called "date"
        date = new Date();
    }

    /**
     * Method printDate() prints the current date to the 
     * terminal window.
     */
    public void printDate()
    {
        //Print the current date to the terminal window
        System.out.println(date.toString());
    }
}

Note, that if you had spent some time searching, you could have found this answer yourself too. For example, the links below are the first two hits of a Google search with the terms "BlueJ return current date". Note they are both from SO!

print current date in java

bluej: how to create object with Date type

Andy
  • 789
  • 8
  • 19