wood burning stoves 2.0*
The moose likes Java in General and the fly likes Formating a Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Formating a Date" Watch "Formating a Date" New topic
Author

Formating a Date

Nathanel Mickaels
Greenhorn

Joined: Aug 26, 2008
Posts: 5
Hallo Java Team,

using SimpleDateFormat i am trying to format a Date to output in German time.
I spent the whole day, still it doesn`t work. Please HELP!
Here is the Codesnipet:

The dates are in the array copiles good but the output doesn`t run
OUTPUT:


What is wrong with my code can someone say something good?

Regards!
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Originally posted by Nathanel Mickaels:
Hallo Java Team,

using SimpleDateFormat i am trying to format a Date to output in German time.
I spent the whole day, still it doesn`t work. Please HELP!
Here is the Codesnipet:

The dates are in the array copiles good but the output doesn`t run
OUTPUT:


What is wrong with my code can someone say something good?

Regards!


Where is einstellungsTag declared?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I think you should do those two statements in the opposite order. Assign a value to einstellungsTag, then use that value.

Also, you should assign the result of the format() method to a String and do something with that String. Your current code just throws away the result of the method.
Nathanel Mickaels
Greenhorn

Joined: Aug 26, 2008
Posts: 5
Hi,
the einstellungsTag is declared as a Date >> private Date einstellungsTag;

There is nothingh wrong with it, because it compiles without any error.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Originally posted by Nathanel Mickaels:
There is nothingh wrong with it, because it compiles without any error.
You haven't been programming very long, have you?



Getting code to compile is only the first step. After that come the rest of the steps, where you try to find out why it doesn't do what you thought it would do.
Nathanel Mickaels
Greenhorn

Joined: Aug 26, 2008
Posts: 5
Hi Paul,
I just changed the order as you said. There is no more Error but the formating doesn`t take over.

What schould i do? here is the result:

thans for help and Regards
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Originally posted by Nathanel Mickaels:
Hi Paul,
I just changed the order as you said. There is no more Error but the formating doesn`t take over.

What schould i do? here is the result:

thans for help and Regards


*Hint* What does the format method return? That's what you should be displaying.

Cheers,
Martijn
Nathanel Mickaels
Greenhorn

Joined: Aug 26, 2008
Posts: 5
Hi,
the format method returns the formated date properly. But i got a for loop to display the output and i know that is what i didn`t get well.

this is how i do it:


and it prints without formating anything. Any idea ?

Regards
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If you are going to format your date inside the constructor of Mitarbeiter, and you want to print the formatted date as an attribute of a Mitarbeiter object, then you need to save the result of the format() method in an instance variable and provide a method in Mitarbeiter which gets that variable.

Or you could put the date formatting code outside Mitarbeiter and call it inside your for-loop.
 
Don't get me started about those stupid light bulbs.
 
subject: Formating a Date