[Hot] How to find out the day of a particular date 2025
Posted: Mon Mar 16, 2026 8:44 pm
Hello, visitor!
Article:
Stack Overflow
How to determine day of week by passing specific date? 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 .
Click here for how to find out the day of a particular date
How can I do"
How to determine day of week by passing specific date? 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? If you're reading this, please skip ahead/down to the answers using the current methodology of java.time! The Calendar-based answers are fine, but outdated now. 29 Answers 29. Yes. Depending on your exact case: You can use java.util.Calendar : if you need the output to be Tue rather than 3 (Days of week are indexed starting at 1 for Sunday, see Calendar.SUNDAY), instead of going through a calendar, just reformat the string: new SimpleDateFormat("EE").format(date) ( EE meaning "day of week, short version") if you have your input as string, rather than Date , you should use SimpleDateFormat to parse it: new SimpleDateFormat("dd/M/yyyy").parse(dateString) you can use joda-time's DateTime and call dateTime.dayOfWeek() and/or DateTimeFormat . edit: since Java 8 you can now use java.time package instead of joda-time. In other things to be careful of, if you set the date in the Calendar object using integers (not via parsing a string), then be aware that the month number is zero-based, so January is 0 and December is 11. @RenniePet: Good one. Also you can use constants in Calendar class, such as Calendar.SUNDAY or Calendar.JANUARY . This answer was a great answer when it was written. Today you will want to the now outdated classes Calendar , Date and DateTimeFormat (and Joda time too) and use the Java 8 java.time classes, for instance YearMonth or LocalDate . See more in this answer. FYI, the troublesome old date-time classes such as java.util.Date , java.util.Calendar , and java.text.SimpleDateFormat are now legacy, supplanted by the java.time classes built into Java 8 & Java 9. See Tutorial by Oracle. Use this code for find the day name from a input date.Simple and well tested. FYI, the troublesome old date-time classes such as java.util.Date , java.util.Calendar , and java.text.SimpleDateFormat are now legacy, supplanted by the java.time classes built into Java 8 & Java 9. See Tutorial by Oracle. 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. See this code run live at IdeOne.com (but only Locale.US works there). java.time. See my example code above, and see the correct Answer for java.time by Przemek. Ordinal number. if just the day ordinal is desired, how can that be retrieved? For ordinal number, consider passing around the DayOfWeek enum object instead such as DayOfWeek.TUESDAY . Keep in mind that a DayOfWeek is a smart object, not just a string or mere integer number. Using those enum objects makes your code more self-documenting, ensures valid values, and provides type-safety. But if you insist, ask DayOfWeek for a number. You get 1-7 for Monday-Sunday per the ISO 8601 standard. Joda-Time. UPDATE: The Joda-Time project is now in maintenance mode. The team advises migrating to the java.time classes. The java.time framework is built into Java 8 (as well as back-ported to Java 6 & 7 and further adapted to Android). Here is example code using the Joda-Time library version 2.4, as mentioned in the accepted answer by Bozho. Joda-Time is far superior to the java.util.Date/.Calendar classes bundled with Java. LocalDate. Joda-Time offers the LocalDate class to represent a date-only without any time-of-day or time zone. Just what this Question calls for. The old java.util.Date/.Calendar classes bundled with Java lack this concept. Parse. Parse the string into a date value. Extract. Extract from the date value the day of week number and name. Dump to console. About java.time. 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.
how to find out the day of a particular date
Article:
Stack Overflow
How to determine day of week by passing specific date? 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 .
Click here for how to find out the day of a particular date
How can I do"
How to determine day of week by passing specific date? 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? If you're reading this, please skip ahead/down to the answers using the current methodology of java.time! The Calendar-based answers are fine, but outdated now. 29 Answers 29. Yes. Depending on your exact case: You can use java.util.Calendar : if you need the output to be Tue rather than 3 (Days of week are indexed starting at 1 for Sunday, see Calendar.SUNDAY), instead of going through a calendar, just reformat the string: new SimpleDateFormat("EE").format(date) ( EE meaning "day of week, short version") if you have your input as string, rather than Date , you should use SimpleDateFormat to parse it: new SimpleDateFormat("dd/M/yyyy").parse(dateString) you can use joda-time's DateTime and call dateTime.dayOfWeek() and/or DateTimeFormat . edit: since Java 8 you can now use java.time package instead of joda-time. In other things to be careful of, if you set the date in the Calendar object using integers (not via parsing a string), then be aware that the month number is zero-based, so January is 0 and December is 11. @RenniePet: Good one. Also you can use constants in Calendar class, such as Calendar.SUNDAY or Calendar.JANUARY . This answer was a great answer when it was written. Today you will want to the now outdated classes Calendar , Date and DateTimeFormat (and Joda time too) and use the Java 8 java.time classes, for instance YearMonth or LocalDate . See more in this answer. FYI, the troublesome old date-time classes such as java.util.Date , java.util.Calendar , and java.text.SimpleDateFormat are now legacy, supplanted by the java.time classes built into Java 8 & Java 9. See Tutorial by Oracle. Use this code for find the day name from a input date.Simple and well tested. FYI, the troublesome old date-time classes such as java.util.Date , java.util.Calendar , and java.text.SimpleDateFormat are now legacy, supplanted by the java.time classes built into Java 8 & Java 9. See Tutorial by Oracle. 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. See this code run live at IdeOne.com (but only Locale.US works there). java.time. See my example code above, and see the correct Answer for java.time by Przemek. Ordinal number. if just the day ordinal is desired, how can that be retrieved? For ordinal number, consider passing around the DayOfWeek enum object instead such as DayOfWeek.TUESDAY . Keep in mind that a DayOfWeek is a smart object, not just a string or mere integer number. Using those enum objects makes your code more self-documenting, ensures valid values, and provides type-safety. But if you insist, ask DayOfWeek for a number. You get 1-7 for Monday-Sunday per the ISO 8601 standard. Joda-Time. UPDATE: The Joda-Time project is now in maintenance mode. The team advises migrating to the java.time classes. The java.time framework is built into Java 8 (as well as back-ported to Java 6 & 7 and further adapted to Android). Here is example code using the Joda-Time library version 2.4, as mentioned in the accepted answer by Bozho. Joda-Time is far superior to the java.util.Date/.Calendar classes bundled with Java. LocalDate. Joda-Time offers the LocalDate class to represent a date-only without any time-of-day or time zone. Just what this Question calls for. The old java.util.Date/.Calendar classes bundled with Java lack this concept. Parse. Parse the string into a date value. Extract. Extract from the date value the day of week number and name. Dump to console. About java.time. 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.
how to find out the day of a particular date