Date to String ?

M

mhk

Hi ,

I want to convert date in to String , i am using following code but
getting error.

***************************************
import java.util.*;
public class date_finder
{
public date_finder() {}

public String get_date ()
{

Date dat = new Date();
String today = String.valueof(dat);
return (today);

}

}

**************************************

Please guide me in correcting this code.

Thanks alot for the help.

Sincerely

Jeff
 
A

Anthony Borla

mhk said:
Hi ,

I want to convert date in to String , i am using following
code but getting error.
Please guide me in correcting this code.

Study the attached code, and post any relevant questions.

I hope this helps.

Anthony Borla
 
M

mhk

Thank you sooooo much. i was using a field length 15 to store date .
Your example helped me to detect my stupid mistake.

Thanks alot

Jeff


**************************************************
Anthony said:
Hi ,

I want to convert date in to String , i am using following
code but getting error.

Please guide me in correcting this code.


Study the attached code, and post any relevant questions.

I hope this helps.

Anthony Borla



import java.util.*;

class TestDateFinder
{
public static void main(String[] args)
{
date_finder df = new date_finder();

System.out.println(df.get_date());
}
}

class date_finder
{
public String get_date()
{
Date dat = new Date();
String today = String.valueOf(dat);
return (today);
}
}
 
J

Joona I Palaste

mhk said:
Thank you sooooo much. i was using a field length 15 to store date .
Your example helped me to detect my stupid mistake.
Thanks alot

Thank *YOU* for quoting his code as real text rather than MIME-
encoded. It's so much easier to read on Usenet.
Anthony, next time please type your code in the message, do not
attach it as a MIME attachment.

Anthony's code, for those who have missed it:
import java.util.*;

class TestDateFinder
{
public static void main(String[] args)
{
date_finder df = new date_finder();

System.out.println(df.get_date());
}
}

class date_finder
{
public String get_date()
{
Date dat = new Date();
String today = String.valueOf(dat);
return (today);
}
}
 
A

Anthony Borla

Joona I Palaste said:
Thank *YOU* for quoting his code as real text rather
than MIME-encoded. It's so much easier to read on
Usenet. Anthony, next time please type your code in the
message, do not attach it as a MIME attachment.

Now, now, Joona, no need for sarcasm ;)

I'm pretty sure [though more from posting experience than seeing citations
in official documents] that proprietary formats [MS Word etc], as well as
open ones such as RTF and HTML are 'no-nos' in Usenet postings, but I was
under the impression that MIME-encoded text was generally acceptable.

I've looked at the following documents:

http://www.faqs.org/faqs/usenet/primer/part1/

and:

http://www.cybernothing.org/cno/docs/rfc1855.html

and have striven to follow the recomendations. Admittedly, though, no
mention is made of MIME-encoded text usage.

Believe me when I say I *do* aim to be considerate of others, hence try to
keep both my message and MIME-encoded text free of control chararcters,
horizontal tabs, and within the recommended line length limits [65 for
message body, 80 [?] for MIME-encoded text]. In fact, the reason I use
MIME-encoded text for *source code* is so that the recipient has a chance to
read code that is legible, with all the indenting intact, something not
often seen when code is included in the message body. AFAIK the only
potential problem with such text is with newline translations, but modern
newsreaders take care of this automatically - am I correct in this
assumption ? Are there other issues - perhaps you could point me to
resources which describe these ?

This is the first complaint I've had about this practice. Thus far I have
assumed readers have quietly benefitted from my posts: I would certainly
like for them to so benefit. I would also like to continue posting using
MIME-encoded text source code as I see it as a very effective means of
sharing source code. However, I will cease to do so if a case against its
use can be made, and not simply be something based solely on following
tradition [i.e. 'don't use MIME because we've never used MIME ...'].

As mentioned earlier, there may well be issues of which I am not aware, and
I'm hoping to be enlightened. I do truly welcome your, and others, views on
this matter.

Cheers,

Anthony Borla
 
S

Sudsy

Anthony said:
This is the first complaint I've had about this practice. Thus far I have
assumed readers have quietly benefitted from my posts: I would certainly
like for them to so benefit. I would also like to continue posting using
MIME-encoded text source code as I see it as a very effective means of
sharing source code. However, I will cease to do so if a case against its
use can be made, and not simply be something based solely on following
tradition [i.e. 'don't use MIME because we've never used MIME ...'].

Actually, I don't mind a bit. I use Netscape to read news and the
attachment name is diplayed in a separate box: it doesn't pollute
the message. You can choose whether or not to view/download the
attachment.
Quite civilized!
 
A

Andrew Thompson

Sudsy said:
Anthony said:
This is the first complaint I've had about this practice. Thus far I have
assumed readers have quietly benefitted from my posts: I would certainly
like for them to so benefit. I would also like to continue posting using
MIME-encoded text source code as I see it as a very effective means of
sharing source code. However, I will cease to do so if a case against its
use can be made, and not simply be something based solely on following
tradition [i.e. 'don't use MIME because we've never used MIME ...'].

Actually, I don't mind a bit.

I had a '..not like that when I were a boy' experience
when I first saw it, but it does make a lot of sense.
Now it is growing on me [ maybe ..like a fungus ;-) ]

I suppose the question comes down to, is there
anybody (or there newsreader) that _cannot_
handle attachments?

Wait.. check this out.
http://groups.google.com/[email protected]

:-(
 
M

Mike

return new Date().toString();

would do it.

Or, to take control over the format:

return new SimpleDateFormat("MMMM dd yyyy - HH:mm:ss").format(new Date());
 
A

Anthony Borla

Andrew Thompson said:
Sudsy said:
Anthony said:
This is the first complaint I've had about this practice. Thus
far I have assumed readers have quietly benefitted from my
posts: I would certainly like for them to so benefit. I would
also like to continue posting using MIME-encoded text source
code as I see it as a very effective means of sharing source code.
However, I will cease to do so if a case against its use can be
made, and not simply be something based solely on following
tradition [i.e. 'don't use MIME because we've never used
MIME ...'].

Actually, I don't mind a bit.

I had a '..not like that when I were a boy' experience
when I first saw it, but it does make a lot of sense.
Now it is growing on me [ maybe ..like a fungus ;-) ]

I suppose the question comes down to, is there
anybody (or there newsreader) that _cannot_
handle attachments?

Exactly how I viewed it. I became quite fed up with well formatted source
code appearing all jumbled and out of alignment, the indenting shot to
pieces. MIME-encoded attachments seemed the *perfect* solution which, with
one major exception [see below], they do seem to be.

Oh - crap :( !!! Not the well formatted text I had hoped would be seen and
enjoyed by all.

Not one to be deterred I conducted a little informal investigation
[basically contacted a few friends using different newsreader software /
working on different platforms], and beleive it is fairly safe to assume [as
I had previously] that MIME-encoded attachments aren't a problem for those
using reasonably recent newsreader software on the common desktop computer
platforms. Of course, this is hardly startling news - I'm sure we all knew
this !

The same goes for private mailing list archives such as you'd find at
academic institutions. Here, provided the mail management software is
correctly configured, MIME-encoded attachments are automatically decoded.
Once again, it doesn't prove to be a problem - if you post an
attachment-laden message, it is perfectly legible, and appears-so even when
archived.

I assumed Google archives to be similarly configured. Unfortunately, I was
mistaken. Reading through this document:

http://groups.google.com/googlegroups/help.html

I happened upon this nugget:

11. Can I access binary content on Google Groups?

No. Google Groups does not archive any binary
content.

Naturally enough, 'binary content' refers also to MIME-encoded attachments
!!! So, I proceeded to:

* Check for archived posts of mine containing such items
* Posted a few test messages to
The results were:

* Messages containing large MIME-encoded attachments
don't appear to be archived. It would seem they are simply
ignored. I was quite disappointed to find that may of my
posts were not archived

* Small attachments seem to 'slip through' and get archived,
but appear in a garbled state; here is an example:



You can check out if interested in what this is
supposed to be !

So, today has been quite an eye-opening experience for me - I have truly
been enlightened :) !

Thank you Joona, Sudsy and Andrew.

Cheers,

Anthony Borla

P.S. I *won't* be MIME(ing) to comp.lang.java.* anytime soon !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top