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 void main(String args[]) {
// Instantiate a Date object
Date date = new Date();
// display time and date using toString()
System.out.println(date.toString());
}
}
It compiles fine. But the output given is:
Date@15db9742
While i am expecting a output like this:
Mon May 04 09:51:52 CDT 2009
What is wrong with the code?
EDIT:
I tried to rename the class.. The editted code:
import java.util.*;
public class DateDemo {
public static void main(String args[]) {
// Instantiate a Date object
Date d = new Date();
// display time and date using toString()
System.out.println(d.toString());
}
}
This is how I compiled the code and ran:
sou@sou-linux:~/Desktop/java$ javac DateDemo.java
sou@sou-linux:~/Desktop/java$ java DateDemo
The output is:
Date@15db9742
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…