code_junkie

How to control the capitalization of month and day names returned by DateFormat?

Nov 10th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public static void main( String[] args )
  2. {
  3. Date date = Calendar.getInstance().getTime();
  4.  
  5. System.out.println("Months:");
  6. printDate( "MMMM", "en", date );
  7. printDate( "MMMM", "es", date );
  8. printDate( "MMMM", "fr", date );
  9. printDate( "MMMM", "de", date );
  10.  
  11. System.out.println("Days:");
  12. printDate( "EEEE", "en", date );
  13. printDate( "EEEE", "es", date );
  14. printDate( "EEEE", "fr", date );
  15. printDate( "EEEE", "de", date );
  16.  
  17. }
  18.  
  19. public static void printDate( String format, String locale, Date date )
  20. {
  21. System.out.println( locale + ": " + (new SimpleDateFormat( format, new Locale( locale ) )).format( date ) );
  22. }
Add Comment
Please, Sign In to add comment