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?
Asked
Active
Viewed 597 times
0
-
`new Date();` ? or for more complexity see `Calendar` or if you are using java8 `LocalDateTime` Did you try searching for this? – Scary Wombat Feb 14 '17 at 01:30
-
How to get a Date on Valentines... – Reimeus Feb 14 '17 at 01:32
-
@Reimeus No idea, I am a developer – Scary Wombat Feb 14 '17 at 01:32
1 Answers
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!

Andy
- 789
- 8
- 19