For Example I have the date: "23/2/2010" (23th Feb 2010). I want to pass it to a function which would return the day of week. How can I do this?
In this example, the function should return String
"Tue".
Additionally, if just the day ordinal is desired, how can that be retrieved?
Calendar class has build-in displayName functionality:
Available since Java 1.6. See also Oracle documentation
Use this code for find the Day name from a input date.Simple and well tested.
Simply use SimpleDateFormat.
The result is: Sat, 28 Dec 2013
The default constructor is taking "the default" Locale, so be careful using it when you need a specific pattern.
One line answer:
Usage Example:
You can try the following code:
There is a challenge on hackerrank Java Date and Time
personally, I prefer the LocalDate class.
There is one video on this challenge.
Java Date and Time Hackerrank solution
I hope it will help :)