Created
February 5, 2014 16:49
-
-
Save rokon12/8828045 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.DateFormatSymbols; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Date; | |
import java.util.Locale; | |
import java.util.Map; | |
/** | |
* @author: bazlur | |
* @since: 2/4/14 6:31 PM | |
*/ | |
public class JavaDayAsString { | |
public static void main(String[] args) { | |
// Pick # 1 | |
String weekDay = ""; | |
Calendar c = Calendar.getInstance(); | |
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); | |
switch (dayOfWeek) { | |
case Calendar.MONDAY: | |
weekDay = "MONDAY"; | |
break; | |
case Calendar.TUESDAY: | |
weekDay = "TUESDAY"; | |
break; | |
case Calendar.WEDNESDAY: | |
weekDay = "WEDNESDAY"; | |
break; | |
case Calendar.THURSDAY: | |
weekDay = "THURSDAY"; | |
break; | |
case Calendar.FRIDAY: | |
weekDay = "FRIDAY"; | |
break; | |
case Calendar.SATURDAY: | |
weekDay = "SATURDAY"; | |
break; | |
case Calendar.SUNDAY: | |
weekDay = "SUNDAY"; | |
break; | |
} | |
System.out.println(weekDay); | |
// Pick # 2 | |
Date now = new Date(); | |
SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE", Locale.US); | |
String asWeek = dateFormat.format(now); | |
System.out.println(asWeek); | |
// Pick # 3 | |
String[] weekdays = new DateFormatSymbols().getWeekdays(); | |
System.out.println(weekdays[now.getDay() + 1]) ; | |
// Pick # 4 | |
Map<String, Integer> displayNames = Calendar.getInstance().getDisplayNames(Calendar.DAY_OF_WEEK, | |
Calendar.LONG, new Locale("en")); | |
System.out.println(displayNames); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment