print current date in java

后端 未结 9 1822
半阙折子戏
半阙折子戏 2020-12-18 19:38

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          


        
9条回答
  •  醉话见心
    2020-12-18 20:31

    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.

提交回复
热议问题