Forums Register Login

Formating a Date

+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
 

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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Hi,
the einstellungsTag is declared as a Date >> private Date einstellungsTag;

There is nothingh wrong with it, because it compiles without any error.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
This will take every ounce of my mental strength! All for a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2685 times.
Similar Threads
Code review required for converting dateformat
Transforming Dates with SimpleDateFormat
problem in incrementing date
How do GregorianCalendars work?
Months and years
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:26:49.