Poniższy kod programu prezentuje przykładowe sposoby formatowania, zarówno ciągu znaków, jak
i wartości numerycznych w oparciu o klasę java.text.MessageFormat. Zapoznaj się z opisem
klasy, a następnie dostosuj sposób wyświetlania daty do formatu rrrr-mm-dd.
import java.text.MessageFormat;
import java.util.Date;
public class FormatowanieRezultatow {
public static void main(String[] args){
String s;
Date teraz = new Date();
String miejsce = "Kraków";
int mila = 1852;
double vat = 0.22;
double cena = 31560.76;
s = MessageFormat.format("{0}, {1,date,full}, godz. {1,time,short}",
miejsce, teraz);
System.out.println(s);
s = MessageFormat.format("{0}kB to {1}B", 256,256*1024);
System.out.println(s);
s = MessageFormat.format("{0} x {0} x {0} = {1}", 7, 7*7*7);
System.out.println(s);
s = MessageFormat.format("{0,number,currency} + VAT({1,number,percent})",
cena, vat);
System.out.println(s);
s = MessageFormat.format("{0} {1} to w przybliżeniu {2}m", 1,
"mila morska", mila);
System.out.println(s);
}
}
Nie rozumiem o co chodzi z tym np. ("{0}, {1,date,full}, godz. {1,time,short}" skąd to się w ogóle bierze i jak to działa, czytałem dokumentację, ale nadal nie czaję.
Jakieś wytłumaczenie tych linii kodu właśnie, wskazówki jakieś, bardzo dziękuję :)