How do I get day of week?
Category: java.util, viewed: 1768 time(s).
In this example we want to create a calendar / date from year and day of the year, because that's all we have. Next we will find what is the day of week of the calendar object is. Let's see the example below.
package org.kodejava.example.java.util; import java.util.Calendar; public class DayOfYearToDayOfWeekExample { public static void main(String[] args) { // Create a calendar with year and day of year. Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2007); calendar.set(Calendar.DAY_OF_YEAR, 180); // See the full information of the calendar object. System.out.println(calendar.getTime().toString()); // Get the weekday and print it int weekday = calendar.get(Calendar.DAY_OF_WEEK); System.out.println("Weekday: " + weekday); } } |
Below is the result of our program.
Fri Jun 29 17:16:22 ICT 2007 Weekday: 6
Related Examples
- How do I sort array values in case insensitive order?
- How do I sort array values in descending order?
- How do I convert milliseconds value to date?
- How do I split a string using Scanner class?
- How do I read file using Scanner class?
- How do I read / write data in Windows registry?
- How do I read user input from console using Scanner class?
- How do I use ResourceBundle for i18n?
- How do I convert time between timezone?
- How do I set a default Locale?
|
|