-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDisplayDay.java
More file actions
34 lines (27 loc) · 884 Bytes
/
DisplayDay.java
File metadata and controls
34 lines (27 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.javamultiplex.datetime;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
//How to display day in different formats?
public class DisplayDay {
public static void main(String[] args) {
Date date=new Date();
DateFormat weekFormat=null;
String day=null;
/*
* u -> day number in Week (1-> Monday, 7-Sunday).
* MM -> Month in digits(1-12)
* E, EE,EEE -> day name in 3 chars
* EEE -> Full day name
*/
weekFormat=new SimpleDateFormat("u");
day=weekFormat.format(date);
System.out.println("Day number in week : "+day);
weekFormat=new SimpleDateFormat("E");
day=weekFormat.format(date);
System.out.println("Day name in 3 chars : "+day);
weekFormat=new SimpleDateFormat("EEEE");
day=weekFormat.format(date);
System.out.println("Full day name : "+day);
}
}