Hi,
I have been dealing a bit with formatting and I have a little thing that puzzles me about printing a time. I have the following code:
import java.util.*;
public class TestFormats {
/**
* @param args
*/
public static void main(
String[] args) {
// TODO Auto-generated method stub
// Create an object of date
Date today = new Date();
// Get the exact time now
String.format("
%tr", today);
// Print the time now (and only the time e.g. 12:12:00 PM)
System.out.println(today);
}
}
According to the book "Head first Java" page 301, it should print the time alone like this:
12:12:00 PM
but....
It prints out the whole date and time like this:
Mon Jan 12 19:44:21 CET 2009
Why is that ?