migger Posted May 17, 2010 Share Posted May 17, 2010 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 More sharing options...
itchytoes Posted May 17, 2010 Share Posted May 17, 2010 Can you display your time in a textField as class="java.util.Date" and then set the pattern attribute to your desired format? (e.g. pattern=pattern="MMMMM dd, yyyy") Link to comment Share on other sites More sharing options...
migger Posted May 18, 2010 Author Share Posted May 18, 2010 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.datepattern: 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 More sharing options...
lucianc Posted May 18, 2010 Share Posted May 18, 2010 miggerWrote: text field expression: ($F{gps_datetime}.getTime()+10800) Isn't new java.util.Date($F{gps_datetime}.getTime()+10800000) what you want?HTH,Lucian Link to comment Share on other sites More sharing options...
migger Posted July 13, 2010 Author Share Posted July 13, 2010 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now