I want to print current date and time in java..This is the code I am trying from a java tutorial:
import java.util.*;
public class Date {
public static
You should not use the toString() method, because:
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
Quote from docs.oracle: http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html).
The Date class is designed to use like everyone else has answered. Just wanted to explain/give you a reference to why.