SimpleDateFormat day format
In this chapter you will learn:
Formatting day using SimpleDateFormat
import java.text.SimpleDateFormat;
import java.util.Date;
/*from java 2 s . com*/
public class Main {
public static void main(String[] args) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("d");
System.out.println("Current day in d format : " + sdf.format(date));
sdf = new SimpleDateFormat("dd");
System.out.println("Current day in dd format : " + sdf.format(date));
}
}
The output:
Formatting day of week using SimpleDateFormat
E
will just show the short form.
EEEE
will make it show the full length.
import java.text.SimpleDateFormat;
import java.util.Date;
/* ja va2s .c o m*/
public class Main {
public static void main(String[] args) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("E");
System.out.println("Day of week in E format : " + sdf.format(date));
sdf = new SimpleDateFormat("EEEE");
System.out.println("Day of week in EEEE format : " + sdf.format(date));
}
}
The output:
Next chapter...
What you will learn in the next chapter:
- Add AM PM to time format using SimpleDateFormat
- Formatting hour using SimpleDateFormat
- Formatting hour using SimpleDateFormat: k
Home » Java Tutorial » Date, Time, Calendar, TimeZone