print current date in java

后端 未结 9 1834
半阙折子戏
半阙折子戏 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:14

    Your class name is Date so

    Date date = new Date();
    

    will create an object of your class and when you call date.toString() it will be the default Object.toString() method.
    So if you have to use the java.util.Date class, rename your Date class to something else

提交回复
热议问题