Google Website Translator Gadget

domingo, 5 de febrero de 2012

Java 7: Formatting text, numbers and dates

Java logo
java.com
Quan estas programant, i sobretot debuggant, es molt interessant poder utilitzar formats al imprimir errors i missatges.
Aixi, pots substituir System.out.println( per System.out.format(

i aplicar els següents modificadors:

nIndependent platform New Line
dA decimal integer.
fA float.
nA new line character appropriate to the platform running the application. You should always use %n, rather than \n.
tBA date & time conversion—locale-specific full name of month.
td, teA date & time conversion—2-digit day of month. td has leading zeroes as needed, te does not.
ty, tYA date & time conversion—ty = 2-digit year, tY = 4-digit year.
tlA date & time conversion—hour in 12-hour clock.
tMA date & time conversion—minutes in 2 digits, with leading zeroes as necessary.
tpA date & time conversion—locale-specific am/pm (lower case).
tmA date & time conversion—months in 2 digits, with leading zeroes as necessary.
tDA date & time conversion—date as %tm%td%ty
 08Eight characters in width, with leading zeroes as necessary.
  +Includes sign, whether positive or negative.
  ,Includes locale-specific grouping characters.
 -Includes Left-justified.
  .3Three places after decimal point.
  10.3Ten characters in width, right justified, with three places after decimal point.

From:  http://docs.oracle.com/javase/tutorial/java/data/numberformat.html

No hay comentarios:

Publicar un comentario