Monday, December 17, 2012

[Java] How do you create a Date for the current time? How do you display the current time?

import the class java.util.Date, and use Date’s no-arg constructor to Create a Date object for the current time. and use the toString() method to display a string represent the Date. For example:
    Date date = new Date();
    System.out.print("Current time:"+date.toString());
To display current time, first use getTime() method in Date class and then call format() method in class SimpleDateFormat to human readable format.
    Date date = new Date();
    SimpleDateFormat time = new SimpleDateFormat("HH:MM a");
    System.out.println("Current time:"+time.format(date.getTime()));
Remarks
Text provided above does not means is the model answer, and it's was posted here for an reference to somebody who interested the related knowledge only. if there is something incorrect, please leave a comment so that i can correct it or for others viewer to have an better reference, if you want know more about this topic and where is the question, concept or answer from, you can reference from information provided under the reference sub-title.

Reference:
Introduction to Java Programming, Y. Daniel Liang 10th 9.14

No comments :

Post a Comment