提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
格式化日历类型值
import java.util.Calendar; import java.util.Locale; /* 来自 *n o w j a v a . c o m - 时 代 Java*/ public class TestFormat { public static void main(String[] args) { long n = 461012; System.out.format("%d%n", n); System.out.format("%08d%n", n); System.out.format("%+8d%n", n); System.out.format("%,8d%n", n); System.out.format("%+,8d%n%n", n); double pi = Math.PI; System.out.format("%f%n", pi); System.out.format("%.3f%n", pi); System.out.format("%10.3f%n", pi); System.out.format("%-10.3f%n", pi); System.out.format(Locale.FRANCE, "%-10.4f%n%n", pi); Calendar c = Calendar.getInstance();/**来自 时 代 J a v a 公 众 号 - N o w J a v a . c o m**/ System.out.format("%tB %te, %tY%n", c, c, c); System.out.format("%tl:%tM %tp%n", c, c, c); System.out.format("%tD%n", c); } }