date_time problum in java??
-
hello guys....This is exactly the same code im copying from a book but yet it producing an exception saying "Can not format given object as Date"...while the author has shown the input in book...
import java.text.*;
import java.util.*;class Date {
public static void main(String [] args) {
Date date = new Date();
SimpleDateFormat sdf;//will show time sdf = new SimpleDateFormat("hh:mm:ss"); //System.out.println(sdf.format(date)); //will show day + date + time sdf = new SimpleDateFormat("dd MMM yyyy hh:mm:ss"); System.out.println(sdf.format(date)); //will show day + date sdf = new SimpleDateFormat("E MMM dd yyyy"); System.out.println(sdf.format(date)); }
}
what is wrong with this code
-
hello guys....This is exactly the same code im copying from a book but yet it producing an exception saying "Can not format given object as Date"...while the author has shown the input in book...
import java.text.*;
import java.util.*;class Date {
public static void main(String [] args) {
Date date = new Date();
SimpleDateFormat sdf;//will show time sdf = new SimpleDateFormat("hh:mm:ss"); //System.out.println(sdf.format(date)); //will show day + date + time sdf = new SimpleDateFormat("dd MMM yyyy hh:mm:ss"); System.out.println(sdf.format(date)); //will show day + date sdf = new SimpleDateFormat("E MMM dd yyyy"); System.out.println(sdf.format(date)); }
}
what is wrong with this code
-
I would say : you shouldn't name the class as Date, since it can be confusing with the Date valuetype.
...
class DateTest {
...
}
thanx.... :)