Re: Newbie Date SimpleDateFormat HELL
From: Tilman Bohn (myfirstname_at_gmx.net)
Date: 02/23/05
- Next message: Tony Dahlman: "Re: Block in synchronized mathod"
- Previous message: Zafar: "HOW TO HANDLE CONTROL_LOGOFF_EVENT handler in JAVA"
- In reply to: Nobody: "Re: Newbie Date SimpleDateFormat HELL"
- Next in thread: Tilman Bohn: "Re: Newbie Date SimpleDateFormat HELL"
- Reply: Tilman Bohn: "Re: Newbie Date SimpleDateFormat HELL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 23 Feb 2005 08:25:10 GMT
In message <MPG.1c85ef1ee80a5d598a0fa@news.verizon.net>,
Nobody wrote on Wed, 23 Feb 2005 06:39:51 GMT:
[...]
>> I don't know what you are trying to do with that Stringbuffer...
>
> Oh, just fumbling through the doc for SimpleDateFormat...
>
> format
>
> public StringBuffer format(Date date,
> StringBuffer toAppendTo,
> FieldPosition pos)
>
> Formats the given Date into a date/time string and appends the result to
> the given StringBuffer.
Ok, I wasn't fully awake when I replied and missed your remark about
wanting to append the date to some other string. But you're thinking
too complicated: just do
sbuf.append( sdf.format( date ) );
and you're done. The overloaded version of format you mention is only
useful if at a later point you need to know at what position in the
formatted StringBuffer a certain field is situated, for example to
align other output on the same column. So if you really want to use
that one, in your case it doesn't matter what FieldPosition you pass
in. You could use new FieldPosition( DateFormat.Field.MILLISECOND ) or
new FieldPosition( DateFormat.Field.YEAR )) or whatever. Even just new
FieldPosition( 0 ) should work just fine, although I'm always in favor
of typesafe enums if they're available. If, however, you really do need
the position of a given field, then use the FieldPosition object from
DateField.Field correspoinding for that particular field. Then you can
later retrieve the position of that field in the formatted string by
calling getBeginIndex() and getEndIndex() on that FieldPosition object.
But as I said, I'd just append to the StringBuffer and be done with
it.
-- Cheers, Tilman `Boy, life takes a long time to live...' -- Steven Wright
- Next message: Tony Dahlman: "Re: Block in synchronized mathod"
- Previous message: Zafar: "HOW TO HANDLE CONTROL_LOGOFF_EVENT handler in JAVA"
- In reply to: Nobody: "Re: Newbie Date SimpleDateFormat HELL"
- Next in thread: Tilman Bohn: "Re: Newbie Date SimpleDateFormat HELL"
- Reply: Tilman Bohn: "Re: Newbie Date SimpleDateFormat HELL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|