Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Adding date and time to a class?

Hi,

I'm currently writing a number of classes to handle video loans etc. The current class, called 'Loans', handles simple information about a loan of a video to a borrower.

My question is simply how do I add the date and time to this class so it is represented with the loan information for a borrower?

My code for this class is currently as follows,

package videos;

import simplejava.*;

public class Loan {

private Borrower borrower;
private Video video;

public Loan() {
this.video = video;
this.borrower = borrower;
}



public String toString() {
return video + "" + borrower;
}

}



Basically, when I call the toString method I need to be able to print out the date and time as well. Any help really appreciated!! :confused:
[957 byte] By [fulcanelli] at [2007-11-11 7:19:35]
# 1 Re: Adding date and time to a class?
what date and time do you want to output?
nspils at 2007-11-11 22:38:48 >
# 2 Re: Adding date and time to a class?
Hi,

Thanks for the reply. I want to be able to add the date and time when the video rental period began, so the current time when the video was rented.

Any ideas?? :confused:
fulcanelli at 2007-11-11 22:39:48 >
# 3 Re: Adding date and time to a class?
look at the methods of java.text.DateFormat - you'll find the way to capture the current time and current date ...
nspils at 2007-11-11 22:40:41 >
# 4 Re: Adding date and time to a class?
Here's an example of how to get current Date and Time:

http://www.javadb.com/?ex=NDM1NDU2MF8xMjkyNTQ1MDc2NjY4NDE1OTI%3D

Hope it helps...

Javaman
javaman at 2007-11-11 22:41:46 >