tl;dr
LocalDate.of( 2026 , 1 , 23 ) // Pass: ( year , month , day )
java.time
Some other Answers are correct in showing how to gather input from the user, but use the troublesome old date-time classes that are now legacy, supplanted by the java.time classes.
LocalDate
For a date-only value without time-of-day and without time zone, use the LocalDate class.
LocalDate ld = LocalDate.of( 2026 , 1 , 23 );
Parse your input strings as integers as discussed here: How do I convert a String to an int in Java?
int y = Integer.parseInt( yearInput );
int m = Integer.parseInt( monthInput ); // 1-12 for January-December.
int d = Integer.parseInt( dayInput );
LocalDate ld = LocalDate.of( y , m , d );

About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
- Java SE 8, Java SE 9, and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and Java SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
- Later versions of Android bundle implementations of the java.time classes.
- For earlier Android, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.
tl;dr
LocalDate.of( 2026 , 1 , 23 ) // Pass: ( year , month , day )
java.time
Some other Answers are correct in showing how to gather input from the user, but use the troublesome old date-time classes that are now legacy, supplanted by the java.time classes.
LocalDate
For a date-only value without time-of-day and without time zone, use the LocalDate class.
LocalDate ld = LocalDate.of( 2026 , 1 , 23 );
Parse your input strings as integers as discussed here: How do I convert a String to an int in Java?
int y = Integer.parseInt( yearInput );
int m = Integer.parseInt( monthInput ); // 1-12 for January-December.
int d = Integer.parseInt( dayInput );
LocalDate ld = LocalDate.of( y , m , d );

About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
- Java SE 8, Java SE 9, and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and Java SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
- Later versions of Android bundle implementations of the java.time classes.
- For earlier Android, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.
Try the following code. I am parsing the entered String to make a Date
// To take the input
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the Date ");
String date = scanner.next();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
Date date2=null;
try {
//Parsing the String
date2 = dateFormat.parse(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(date2);
Videos
Here's javadoc for next(), this is what it says:
Finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern.
Default delimiter is space and hence, it only reads 27. You need to read the whole line by using nextLine(). Following should work:
System.out.println("Enter check-in date (dd/mm/yy):");
String cindate = input.nextLine();
if(null != cindate && cindate.trim().length() > 0){
Date date1 = myFormat.parse(cindate);
}
Update To check for null or empty string, you need to wrap the parsing code inside if condition.
Other answers addressed how to use Scanner correctly. I'll address some other issues.
java.time
You are using troublesome old date-time classes, now legacy, supplanted by the java.time classes. Avoid the java.util.Date class like the Plague.
Also, you are inappropriately trying to represent a date-only value with a date+time class.
Instead, use java.time.LocalDate. The LocalDate class represents a date-only value without time-of-day and without time zone.
To parse the user's input, specify a formatting pattern to match exactly the expected input from your user.
DateTimeFormatter f = DateTimeFormatter.parse( "dd/mm/uuuu" );
Parse user input.
LocalDate ld = LocalDate.parse( input , f );
On your business class Guest, make the member variable of type LocalDate.
To persist the LocalDate, you can serialize to text in standard ISO 8601 format. Simply call toString.
String output = guest.getLocalDate().toString();
2017-01-23
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
- Java SE 8 and SE 9 and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
- The ThreeTenABP project adapts ThreeTen-Backport (mentioned above) for Android specifically.
- See How to use ThreeTenABP….
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.
I've been working on using the Scanner to input information for a constructor. I have a majority of it down except for the Date object. I've tried using the DateTimeFormatter and the SimpleDateFormat but can't get it to work properly. I've had an unparsable date with the DateTimeFormatter and now I have a String cannot be converted to Date error. Any help for this part?
String hireDate = scanner.next();
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date date = formatter.parse(hireDate);
import java.text.DateFormat;
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Scanner;
public static void main(String[] args) throws ParseException {Scanner scanner = new Scanner(System.in);
//input the following information System.out.println("Employee First Name"); String firstName = scanner.nextLine(); System.out.println("Employee Last Name"); String lastName = scanner.nextLine(); System.out.println("Employee Number"); int employeeNumber = scanner.nextInt(); System.out.println("Hire Date");
//problem area String hireDate = scanner.next(); DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date date = formatter.parse(hireDate);
Employee a = new Employee(firstName, lastName, employeeNumber, hireDate);
}}
Here is the other class I am using as well.
public class Employee {
public String firstName;
public String lastName;
public int employeeNumber;
public Date hireDate;
public Employee(String firstName, String lastName, int employeeNumber, Date hireDate){
this.firstName= firstName;
this.lastName = lastName;
this.employeeNumber= employeeNumber;
this.hireDate= hireDate;}
public String getEmployeeFirstName(){
return firstName;}
public void setEmployeeFirstName(String firstName){
this.firstName= firstName;}
public String getEmployeeLastName(){
return firstName;}
public void setEmployeeLastName(String lastName){
this.lastName= lastName;}
public int getEmployeeNumber(){
return employeeNumber;}
public void setEmployeeNumber(int employeeNumber){
this.employeeNumber= employeeNumber;}
public Date getHireDate(){
return hireDate;}
public void setHireDate(Date hireDate){
this.hireDate= hireDate;}
public String toString() {
String str = "Employee Name: " + firstName + " " +lastName +
"\nEmployee Number: " + employeeNumber +
"\nEmployee Hire Date: " + hireDate;
return str;
}}
I suggest u to use a simple Bean ZodiacSign like that:
class ZodiacSign {
private String name;
private int startMonth;
private int startDay;
private int endMonth;
private int ednDay;
public ZodiacSign(String name, int startMonth, int startDay, int endMonth, int ednDay) {
super();
this.name = name;
this.startMonth = startMonth;
this.startDay = startDay;
this.endMonth = endMonth;
this.ednDay = ednDay;
}
// getter & setter
}
and iterate over a collection until you find a match, like this:
List<ZodiacSign> zodiac = Collections.emptyList();
zodiac.add(new ZodiacSign("AQUARIUS", Calendar.JANUARY, 20, Calendar.FEBRUARY, 18));
zodiac.add(new ZodiacSign("PISCES", Calendar.FEBRUARY, 19, Calendar.MARCH, 20));
// ..
zodiac.add(new ZodiacSign("CAPRICORN", Calendar.DECEMBER, 22, Calendar.JANUARY, 19));
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
int month = calendar.get(Calendar.MONTH);
for (ZodiacSign sign : zodiac) {
if (month >= sign.getStartMonth() && month <= sign.getEndMonth()) {
if (dayOfMonth >= sign.getStartDay() && dayOfMonth <= sign.getEdnDay()) {
System.out.println("Zodiac Sign: " + sign.getName());
}
}
}
You can do it like this
public static void main(String[] args) throws ParseException {
Scanner userInput = new Scanner(System.in);
System.out.println("Hello you, Lets get to know each other");
String userName;
System.out.println("What is your name ?");
userName = userInput.nextLine();
System.out.println(userName + " please enter you DoB (DD/MM/YYY)");
String dateOB = userInput.next();
Date date = new SimpleDateFormat("dd/MM/yyyy").parse(dateOB);
System.out.println(dateOB);
System.out.println("So your date of birth is " + dateOB);
Calendar c = Calendar.getInstance();
c.setTime(date);
int day = c.get(Calendar.DAY_OF_YEAR);
// IF day is from January 20 - to February 18 this means he or she is aquarius
if (day >= 20 && day <= 49) {
System.out.println("Aquarius");
} else if (day >= 50 && day <= 79) {
//If day if from February 19 to March 20 then pisces
System.out.println("Pisces");
}
//write all zodiac signs ...
userInput.close();
}
You have defined the simpleDateFormat but dont seem to have used it. It will specifically serve what you need.
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(sdf.format(yourDate));
You need to add this logic inside
public String getItem() {
return theTitle + ", " + sdf.format(theDate) + ", " + theTime + ", " + theLocation + ", " + theDuration + ", " + theCategory;
}
Since you hadnt specified anything there, it was calling the Date.toString() method while string concatenation.
I recommend you switch from the outdated and error-prone java.util date-time API to the rich set of modern date-time API.
Define a formatter object:
DateTimeFormatter.ofPattern("dd/MM/yyyy")
…and use that same DateTimeFormatter object for both parsing and generating text.
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
public class Main {
public static void main(final String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter date in the format dd/MM/yyyy: ");
String dateStr = scanner.nextLine();
// Define a formatter
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
// Parse the date string to LocalDate using the formatter
LocalDate theDate = LocalDate.parse(dateStr, formatter);
// Whenever you need to display it, display it using the same formatter
String backToStr = formatter.format(theDate);
System.out.println(backToStr);
}
}
A sample run:
Enter date in the format dd/MM/yyyy: 21/07/2020
21/07/2020
A side note: I can see that you have created a new instance of Scanner for every input. You should create just one instance of Scanner and use the same instance for every input.