Re: Help with Date and SimpleDateFormat
From: VisionSet (spam_at_ntlworld.com)
Date: 10/21/03
- Next message: Stern: "Re: Find duplicates"
- Previous message: Joerg Gippert: "Re: Credit card validation class -> thanks"
- In reply to: Kyote: "Re: Help with Date and SimpleDateFormat"
- Next in thread: Kyote: "Re: Help with Date and SimpleDateFormat"
- Reply: Kyote: "Re: Help with Date and SimpleDateFormat"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 21 Oct 2003 12:14:52 +0100
"Kyote" <looking@you.com> wrote in message
news:ksn8pv44ct8m0gkt3tap778p61v3c9kqme@4ax.com...
> What I was trying to do was learn to understand Date. Now, instead of
> being passed a string and converting it into a date, I find that I am
> being passed a Calendar object. They changed things on me.
>
> So now I have some different problems. Here's what I have so far.
>
> public void setRequestedDate(Calendar param) {
> String c =
> param.get(Calendar.MONTH)
> + "/"
> + param.get(Calendar.DAY_OF_MONTH)
> + "/"
> + param.get(Calendar.YEAR)
> + " "
> + param.get(Calendar.HOUR_OF_DAY)
> + ":"
> + param.get(Calendar.MINUTE);
>
> }
>
> I have no clue if I'm doing this right. I'd really like to be able to
> create a main to test this out so I can continue to experiment, but,
> I'm at a loss as to how to do so. Please, any help would be highly
> appreciated!!
>
>
At one point you said this:
>Okay, what I'm trying to do is to send a string and convert it to a
>date and then format it. Apparently I don't understand the API at
>ALL.... :(
this is the only time you have really tried to say what you want to do. Is
this still what you want? Because if it is, it seems that you now have it.
If you have a Calendar object ie param, then you just get a Date object with
getTime(). If you want to format it then just do:
> >SimpleDateFormat sdf = new SimpleDateFormat("M/d/yyyy hh:mm");
> >String dd = sdf.format(param.getTime());
> >System.out.println(dd);
You can do all that manual concatenation you are doing, but the Format
classes make this unnecessary, hence the new pattern above: "M/d/yyyy hh:mm"
With the main you require to test just do:
public static void main(String[] args) {
ThisClass a = new ThisClass();
a.setRequestedDate(new GregorianCalendar());
}
but your setRequestedDate method is not setting anything!
Is this what you want to do? Set a Calendar object to a certain date?
Perhaps you could try to express clearly what you want to do!
-- Mike W
- Next message: Stern: "Re: Find duplicates"
- Previous message: Joerg Gippert: "Re: Credit card validation class -> thanks"
- In reply to: Kyote: "Re: Help with Date and SimpleDateFormat"
- Next in thread: Kyote: "Re: Help with Date and SimpleDateFormat"
- Reply: Kyote: "Re: Help with Date and SimpleDateFormat"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|