Java Reference
In-Depth Information
If the argument value for a floating-point conversion is NaN or Infinity , the output contains the strings "NaN"
and "Infinity" , respectively. The following snippet of code shows the formatting of floating-point numbers when
their values are NaN or infinities:
System.out.printf("%.2e %n", Double.NaN);
System.out.printf("%.2f %n", Double.POSITIVE_INFINITY);
System.out.printf("%.2g %n", Double.NEGATIVE_INFINITY);
System.out.printf("%(f %n", Double.POSITIVE_INFINITY);
System.out.printf("%(f %n", Double.NEGATIVE_INFINITY);
NaN
Infinity
-Infinity
Infinity
(Infinity)
Formatting Dates and Times
Date/time formatting deals with formatting date, time, and datetime. It can be applied to format values of long , Long ,
java.util.Calandar , java.util.Date , and java.time.temporal.TemporalAccessor types. The value in a long / Long
type argument is interpreted as the milliseconds passed since January 1, 1970 midnight UTC.
TemporalAccessor is an interface added in Java 8. it is part of the new Date-time api. all classes in the api
that specify some kind of date, time, or both are TemporalAccessor. LocalDate , LocalTime , LocalDateTime , and
ZonedDateTime are some examples of TemporalAccessor . please refer to Chapter 12 for more details on using the new
Date-time api.
Note
The 't' conversion character is used to format date/time values. It has an uppercase variant 'T' . The general
syntax for a format specifier for date/time formatting is as follows:
%<argument_index$><flags><width><conversion>
Note that precision part in a format specifier is not applicable to date/time formatting. For date/time formatting,
the conversion is a two-character sequence. The first character in the conversion is always 't' or 'T' . The second
character is called the conversion suffix, which determines the format of the date/time argument. Table 13-7 , 13-8 and
Table 13-9 list all the conversion suffixes that can be used with 't' / 'T' data/time conversion character.
 
 
Search WWH ::




Custom Search