Example usage for java.util Formatter format

List of usage examples for java.util Formatter format

Introduction

In this page you can find the example usage for java.util Formatter format.

Prototype

public Formatter format(String format, Object... args) 

Source Link

Document

Writes a formatted string to this object's destination using the specified format string and arguments.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Formatter fmt = new Formatter();
    Calendar cal = Calendar.getInstance();

    fmt.format("Time using 12-hour clock: %tr\n", cal);
    System.out.println(fmt);/*w  w w . j  a v a 2s. c  om*/

}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();
    Calendar cal = Calendar.getInstance();

    fmt.format("%tr", cal);
    System.out.println(fmt);//from   w  w  w  .  j  a  va  2 s . co  m

}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    // Display standard 12-hour time format.
    fmt.format("%tr", Calendar.getInstance());
    System.out.println(fmt);/*from   w  w w  .j a va 2s.c  o m*/

}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();
    Calendar cal = Calendar.getInstance();

    fmt.format("Today is day %te of %<tB, %<tY", cal);
    System.out.println(fmt);/*from  w w  w .j av a 2s .  c  om*/
}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    // Right justify by default 
    fmt.format("|%10.2f|", 123.123);
    System.out.println(fmt);//from  w  ww . j  av  a  2 s .  c o m

    // Now, left justify. 
    fmt = new Formatter();
    fmt.format("|%-10.2f|", 123.123);
    System.out.println(fmt);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Formatter fmt = new Formatter();
    Calendar cal = Calendar.getInstance();

    fmt.format("Time and date in lowercase: %tc\n", cal);
    fmt.format("Time and date in uppercase: %Tc\n", cal);

    System.out.println(fmt);//from   w w  w . j  a va  2  s . co m
}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    for (double i = 1000; i < 1.0e+10; i *= 100) {
        fmt.format("%g ", i);
        System.out.println(fmt);//from  ww w  . ja  v a2s.  c  o  m
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    // Format 4 decimal places.
    fmt.format("%.4f", 123.1234567);
    System.out.println(fmt);//w ww.ja  v a  2 s  .c  o  m

    // Format to 2 decimal places in a 16 character field.
    fmt = new Formatter();
    fmt.format("%16.2e", 123.1234567);
    System.out.println(fmt);

    // Display at most 15 characters in a string.
    fmt = new Formatter();
    fmt.format("%.15s", "Formatting with Java is now easy.");
    System.out.println(fmt);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Formatter fmt = new Formatter();
    Calendar cal = Calendar.getInstance();
    System.out.println(fmt.format("Short date format: %tD\n", cal));
}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();
    // Format 4 decimal places.
    fmt = new Formatter();
    fmt.format("%16.2e", 123.1234567);
    System.out.println(fmt);/*from  w w  w  .  j a va2 s  .c o m*/
}