I have a simple class called DateTime because I'm doing some interface with a C# web service. I wanted to override the Date class' toString method as shown below in order to serialize it in a way C# understands, so I wrote a simple little wrapper class. The problem comes when trying to cast a Date type as DateTime. Is there any way to do something along the lines of:
(DateTime)Calendar.getInstance().getTime();
I tried the above cast and got a ClassCastException. Is there any way to do this or something similar? My class definition is below.
private class DateTime extends Date {
@Override
public String toString() {
int year= getYear();
int month= getMonth();
int day= getDay();
int hour= getHours();
int minute= getMinutes();
int second= getSeconds();
return String.format("%04d-%02d-%02dT%02d:%02d:%02d", year, month, day, hour, minute, second);
}
}