Use a custom format for Date value : MessageFormat « Development Class « Java






Use a custom format for Date value


import java.text.MessageFormat;
import java.util.Date;

public class Main {
  public static void main(String[] argv) throws Exception {
    Object[] params = new Object[] { new Date(), new Date(0) };
    String msg = MessageFormat
        .format("{0,time,HH-mm-ss} and UTC of 0 is {1,time,HH-mm-ss}", params);

    System.out.println(msg);
  }
}
// 08-32-33 and UTC of 0 is 16-00-00

 








Related examples in the same category

1.Substitute tokens in a String
2.Formatting a Message Containing a Number
3.Format message with Integer fillers
4.Use a custom format
5.Floating point numbers
6.Currency number format
7.Percent value format
8.Formatting a Message Containing a Time
9.Format Date() in short format
10.Format Date() value in medium format
11.Format Date() in long
12.Format Date value in full length
13.Formatting a Message Containing a Date
14.Combine date value in a sentence
15.Date value short format
16.Medium length format for Date value
17.Long style format for Date value
18.Full length format for Date value