I have a date of when a file was last updated, so it is a long, and I need to put it in a Sybase database as a datetime field. I used the toString method of the Date object to get a string, and it worked, but it did not give me the time, only the date, so when I put it into the database, the time defaulted to 12:00AM. I need to create a string that has the date and time, and I do not see a method for the Date class that does that. Can anyone help here, Thanks in advance! Rob
I am getting: 2002-08-12 from: long file_time = file_name.lastModified(); Date date = new Date( file_time ); System.out.println( date.toString() ); I do not know why I am not getting the time along with the date. Thanks in advance!!
Joined: Jul 18, 2002
Hmm, according to here, you should see an output of the form: dow mon dd hh:mm:ss zzz yyyy Is your Date a java.util.Date? Check the imports for your code?
You've got a java.sql.Date, not a java.util.Date. The API specifies the format of toString() for each type; you've got the former. Probably you should either replace "import java.sql.*;" with a series of specific class imports (not including java.sql.Date) or replace every "Date" with "java.util.Date".
"I'm not back." - Bill Harding, Twister
Joined: Oct 01, 2000
Thanks Neil and Jim, that was it.
Joined: Jan 30, 2000
Hey, don't forget Marilyn. She did try to draw your attention to this issue earlier.