forked from ronijpandey/Java-Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added JavaDateAndTime.java ronijpandey#2
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.util.Arrays; | ||
import java.util.Calendar; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
public class JavaDateAndTime { | ||
static List<String> days = Arrays.asList("SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"); | ||
|
||
public static String getDay(String day, String month, String year) { | ||
|
||
int y = Integer.parseInt(year); | ||
int m = Integer.parseInt(month); | ||
int d = Integer.parseInt(day); | ||
|
||
Calendar c = Calendar.getInstance(); | ||
c.set(y, m-1, d); | ||
|
||
int p = c.get(Calendar.DAY_OF_WEEK); | ||
String s = days.get(p-1); | ||
return s; | ||
} | ||
|
||
public static void main(String[] args) { | ||
Scanner in = new Scanner(System.in); | ||
String month = in.next(); | ||
String day = in.next(); | ||
String year = in.next(); | ||
|
||
System.out.println(getDay(day, month, year)); | ||
|
||
} | ||
} |