Jump to content

How to offset timestamps into wanted timezone


migger

Recommended Posts

Hi,

I am trying to get localized time based on user's browser clock settings to my report. I am getting time offset from UI to server and can pass it with parameter to my template filling, but it seems I don't know how I could alter the timestamps I am fetching from the database with the offset.

I have saved the timestamps in database in GMT time (java.sql.timestamp without timezone). Now I am able to do following (to text field expression):

Long.valueOf(($F{gps_datetime}.getTime()+10800))

Which gives me the time in milliseconds with added offset (3 hours in this case), but I don't know how I could convert it back to YYYY-MM-DD HH:MM:SS format.

 

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Maybe I could, but there is no help for me since there is no "automatic conversion" for time in milleseconds (or seconds) since epoch to time in date (or timestamp) format. I would need a way to convert the time to date format with the added timezone offset. I think I can't do it with just pattern (I get error that I can't cast from long to date)? Or did I misunderstood your suggestion itchytoes?

I did following:

text field expression: ($F{gps_datetime}.getTime()+10800)

expression class: java.util.date

pattern: dd/MM/yyyy HH.mm.ss (it is not that important how it is precisely as long as I am able to convert from milliseconds to date format)

And I got that Cannot cast from long to Date.

Maybe I should create some variable to the report or something similar?

Link to comment
Share on other sites

  • 1 month later...

Thanks Lucian! Your solution led me to solve this one, final solution was following:

new java.sql.Timestamp($F{gps_datetime}.getTime()+$P{timeShift}.longValue())

Java Date object omits the clock time, so Timestamps was the one to use.

Thanks again and hopefully this also helps someone else who has been fighting with the similar problem...

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...