Format cells to show dates as the day of the week Under Category, click Custom, and in the Type box, type dddd for the full name of the day of the week (Monday, Tuesday, and so on), or ddd for the abbreviated name of the day of the week (Mon, Tue, Wed, and so on).
The dates appear as, mm/dd/yyyy in the U.S. and as, dd/mm/yyyy outside the U.S. where mm is the month, dd is the day, and yyyy is the year. The time is displayed as, hh:mm:ss AM/PM, where hh is the hour, mm is minutes, and ss is seconds.
Java SimpleDateFormat with Locale String pattern = "EEEEE MMMMM yyyy HH:mm:ss. SSSZ"; SimpleDateFormat simpleDateFormat =new SimpleDateFormat(pattern, new Locale("fr", "FR")); String date = simpleDateFormat. format(new Date()); System.
This should display 'Tue':
new SimpleDateFormat("EEE").format(new Date());
This should display 'Tuesday':
new SimpleDateFormat("EEEE").format(new Date());
This should display 'T':
new SimpleDateFormat("EEEEE").format(new Date());
So your specific example would be:
new SimpleDateFormat("yyyy-MM-EEE").format(new Date());
Yep - 'E' does the trick
http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-E");
System.out.println(df.format(date));
LocalDate.of( 2018 , Month.JANUARY , 23 )
.format( DateTimeFormatter.ofPattern( “uuuu-MM-EEE” , Locale.US ) )
The modern approach uses the java.time classes.
LocalDate ld = LocalDate.of( 2018 , Month.JANUARY , 23 ) ;
Note how we specify a Locale
such as Locale.CANADA_FRENCH
to determine the human language used to translate the name of the day.
DateTimeFormatter f = DateTimeFormatter.ofPattern( “uuuu-MM-EEE” , Locale.US ) ;
String output = ld.format( f ) ;
By the way, you may be interested in the standard ISO 8601 week numbering scheme: yyyy-Www-d
.
2018-W01-2
Week # 1 has the first Thursday of the calendar-year. Week starts on a Monday. A year has either 52 or 53 weeks. The last/first few days of a calendar-year may land in the next/previous week-based-year.
The single digit on the end is day-of-week, 1-7 for Monday-Sunday.
Add the ThreeTen-Extra library class to your project for the YearWeek
class.
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?
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.
SimpleDateFormat sdf=new SimpleDateFormat("EEE");
EEE stands for day of week for example Thursday is displayed as Thu.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With