Program to get name of Day by entering year, month, date.

In this program, we will see the code to get name of Day by entering year, month and date.

LocalDate:

java.time public final class LocalDate
extends Object
implements java.time.temporal.Temporal, java.time.temporal.TemporalAdjuster,

A date without a time-zone in the ISO-8601 calendar system, such as 2007-12-03.

LocalDate is an immutable date-time object that represents a date, often viewed as year-month-day. Other date fields, such as day-of-year, day-of-week and week-of-year, can also be accessed. For example, the value "2nd October 2007" can be stored in a LocalDate.


ADVERTISEMENT


This class does not store or represent a time or time-zone. Instead, it is a description of the date, as used for birthdays. It cannot represent an instant on the time-line without additional information such as an offset or time-zone.
The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time. For most applications written today, the ISO-8601 rules are entirely suitable. However, any application that makes use of historical dates, and requires them to be accurate will find the ISO-8601 approach unsuitable.

This is a value-based class; use of identity-sensitive operations (including reference equality (==), identity hash code, or synchronization) on instances of LocalDate may have unpredictable results and should be avoided. The equals method should be used for comparisons.

Code:

import java.time.LocalDate;
import java.util.Scanner;

class GetDay {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int yy,mm,dd;

System.out.println("Enter year: ");
yy=sc.nextInt();

System.out.println("Enter Month: ");
mm=sc.nextInt();

System.out.println("Enter date: ");
dd=sc.nextInt();

LocalDate lt = LocalDate.of(yy,mm,dd);

System.out.println("Day :"+lt.getDayOfWeek());

}

}

Output:

Enter year:
2020
Enter Month:
07
Enter date:
28
Day :TUESDAY

Process finished with exit code 0

Also read:
Previous Post Next Post

Contact Form