Yes. Depending on your exact case:
- You can use
java.util.Calendar
:Calendar c = Calendar.getInstance(); c.setTime(yourDate); int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
- 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 useSimpleDateFormat
to parse it:new SimpleDateFormat("dd/M/yyyy").parse(dateString)
- you can use joda-time’s
DateTime
and calldateTime.dayOfWeek()
and/orDateTimeFormat
. - edit: since Java 8 you can now use java.time package instead of joda-time
Related Posts:
- Java string to date conversion
- Change date format in a Java string
- How to compare dates in Java?
- Convert java.util.Date to String
- LocalDate to java.util.Date and vice versa simplest conversion?
- How to get today’s Date?
- How to convert currentTimeMillis to a date in Java?
- Adding days to a date in Java
- How to convert an Instant to a date format?
- Sort ArrayList of custom Objects by property
- Set Date in a single line
- How to convert a date to milliseconds
- Get integer value of the current year in Java
- How to convert java.util.Date to java.sql.Date?
- Java 8 Iterable.forEach() vs foreach loop
- How to round a number to n decimal places in Java
- Error unable to access jarfile C:\Jar
- In laymans terms, what does ‘static’ mean in Java? [duplicate]
- Sort an array in Java
- Java String Split by “|”
- Could not reserve enough space for object heap
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse
- “Char cannot be dereferenced” error
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
- Print ArrayList
- Unsupported major.minor version 52.0 [duplicate]
- What is a StringIndexOutOfBoundsException? How can I fix it?
- Non-static variable cannot be referenced from a static context
- How to get an enum value from a string value in Java
- Round a double to 2 decimal places [duplicate]
- Int division: Why is the result of 1/3 == 0?
- Unfortunately MyApp has stopped. How can I solve this?
- What is the significance of load factor in HashMap?
- Which HTML Parser is the best?
- Returning Arrays in Java
- java.lang.ClassCastException
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘MyController’:
- Can I multiply strings in Java to repeat sequences?
- Why does cache use Most Recently Used (MRU) algorithm as evict policy?
- javac not working in windows command prompt
- Java returns error “Cannot instantiate the type”
- How to for each the hashmap?
- Why do I get SQLCODE=-204, SQLSTATE=42704 with DB2 LUW and WebSphere App Server?
- java.net.UnknownHostException: Invalid hostname for server: local
- HashMap get/put complexity
- @Autowired – No qualifying bean of type found for dependency
- SSH library for Java
- Java ArrayList replace at specific index
- Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
- What is the best math library to use with java?
- How to execute a https GET request from java
- Double decimal formatting in Java
- Converting JSON to XML in Java
- Import a custom class in Java
- Default keystore file does not exist?
- The declared package does not match the expected package “”
- Sort a Map
by values - Is not an enclosing class Java
- FtpClient storeFile always return False
- Variable is accessed within inner class. Needs to be declared final
- Using NotNull Annotation in method argument
- How to implement infinity in Java?
- Java Does Not Equal (!=) Not Working?
- How to represent empty char in Java Character class
- Definition of a Java Container
- How do I draw a triangle?
- Java path..Error of jvm.cfg
- How to fix the compiler error in this program?
- “The public type <
> must be defined in its own file” error in Eclipse [duplicate] - How to calculate the intersection of two sets?
- method does not override method in its superclass
- Adding a timer to my program (javafx)
- How to resolve Unable to load authentication plugin ‘caching_sha2_password’ issue
- Deleting an object in java?
- Recompile with -Xlint:deprecation for details
- How to determine an object’s class?
- Division of integers in Java
- Consider this code: “int s = 20; int t = s++ + –s;”. What are the values of s and t?
- Reading a .txt file using Scanner class in Java
- “\b” in Java – Windows implemented
- Error: package or namespace load failed for ‘rJava’
- Difference between regex [A-z] and [a-zA-Z]
- package org.json does not exist when importing org.json.JSONObject
- How to add an element at the end of an array?
- Fields in interfaces
- How to print out all the elements of a List in Java?
- How to send data to COM PORT using JAVA?
- Python-like list comprehension in Java
- Can an int be null in Java?
- What’s the difference between HashSet and Set?
- Netbeans – Error: Could not find or load main class
- Eclipse IDE – Error: Build path specifies execution environment Java SE 1.7
- Java Iterator on Doubly-linked-list
- Why “no projects found to import”?
- Java Swing setting JPanel Size
- how to use “tab space” while writing in text file
- Change Name of Import in Java, or import two classes with the same name
- set background color: Android
- Class JavaLaunchHelper is implemented in two places
- No Main class found in NetBeans