Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formating a Date

 
Nathanel Mickaels
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Clapham
Sheriff
Posts: 20713
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20713
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20713
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic