|
NOTA: La traducción de esta documentación es un esfuerzo personal y voluntario, no es un documento oficial de Sun Microsystems
ni Oracle ni está patrocinado por ninguna de estas empresas. Los documentos originales (en inglés) están disponibles en:
http://java.sun.com/docs/books/tutorial/.
Dirija cualquier comentario, petición, felicitación, etc. a tutorialesjava_@RROBA_codexion.com. |
Si desea ayudar a mantener en funcionamiento esta web, colaborar con la traducción de estos documentos o necesita que se traduzca algĂșn capĂtulo en concreto puede realizar una donación directa mediante Paypal:
|
Theformatmethod of theSimpleDateFormatclass returns aStringcomposed of digits and symbols. For example, in theString"Friday, April 10, 1998," the symbols are "Friday" and "April." If the symbols encapsulated inSimpleDateFormatdon't meet your needs, you can change them with theDateFormatSymbols. You can change symbols that represent names for months, days of the week, and time zones, among others. The following table lists theDateFormatSymbolsmethods that allow you to modify the symbols:
DateFormatSymbolMethodsSetter Method Example of a Symbol the Method Modifies setAmPmStringsPM setErasAD setMonthsDecember setShortMonthsDec setShortWeekdaysTue setWeekdaysTuesday setZoneStringsPST The following example invokes
setShortWeekdaysto change the short names of the days of the week from lowercase to uppercase characters. The full source code for this example is inDateFormatSymbolsDemo. The first element in the array argument ofsetShortWeekdaysis a nullString. Therefore the array is one-based rather than zero-based. TheSimpleDateFormatconstructor accepts the modifiedDateFormatSymbolsobject as an argument. Here is the source code:Date today; String result; SimpleDateFormat formatter; DateFormatSymbols symbols; String[] defaultDays; String[] modifiedDays; symbols = new DateFormatSymbols(new Locale("en","US")); defaultDays = symbols.getShortWeekdays(); for (int i = 0; i < defaultDays.length; i++) { System.out.print(defaultDays[i] + " "); } System.out.println(); String[] capitalDays = { "", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; symbols.setShortWeekdays(capitalDays); modifiedDays = symbols.getShortWeekdays(); for (int i = 0; i < modifiedDays.length; i++) { System.out.print(modifiedDays[i] + " "); } System.out.println(); System.out.println(); formatter = new SimpleDateFormat("E", symbols); today = new Date(); result = formatter.format(today); System.out.println(result);The preceding code generates this output:
Sun Mon Tue Wed Thu Fri Sat SUN MON TUE WED THU FRI SAT WED