Jump to content

Wrong MySQL timestamp with SimpleDateFormat


DarkRaven

Recommended Posts

Hi !

 

I've a problem with the integration of MySQL timestamps in the iReports. A normal MySQL timestamp looks like this 1195642306 (translation: 21.11.2007 - 11:51:46 (german format)).

I selected the databasefield in iReport as java.sql.timestamp and used the following code in a TextField of iReport: new SimpleDateFormat("dd.MM.yyyy - HH:mm:ss").format($F{logs_timestamp})

But the values didn't match. For the example timestamp (above) the result is 03.01.2019 - 23:06:00.

What is wrong ? I've no idea ! :blink:

 

Greets

Christian

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Ok, I think I've found the problem, but did not know how to cast.

After adding a secound TextField in the report with the code: $F{logs_timestamp}.toString()

I'm able to see the roughly data from the timestamp. It sais: 2019-1-03 23:06:00.0

So this seems to be a wrong type cast. Did you know how I can cast the timestamp from string to java.sql.timestamp ? :huh:

Link to comment
Share on other sites

Have you try with the pattern on the textfield property. I've solve all my date problems with that.

 

Go to, textfield properties and in the TextField tab you'll see a pattern you can get help from the create button is pattern editor. let me know how it goes please

Link to comment
Share on other sites

Hi !

 

Ok, I tried so, but this has the same effect. I found some information about the timestamp format which is used in java.sql.timestamp. You have to change the MySQL table field value to timestamp. Then it looks like 05-04-2007 12:15:04.3 and only then you can use it with iReport and SimpleDateFormat or with the pattern.

I'll try this... :woohoo:

Link to comment
Share on other sites

[color=#FF0000]SOLVED !!![/color]

Damned ! That's it !

You have to change the databasefield to type:timestamp. But be careful ! This change deletes all values in the timestamp fields at first ! So it's good to have a test server ! :whistle:

Thanks to all helping hands ! ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...