I have a database that holds times at which i need to run certain processes
I do a query which gives me the difference between the current time and the time at which i’m supposed to run the process
For example, I might get this number 23:49:44.835 which means i need to run the process in about 23 hours.
I want to get this process in milliseconds, so I have done this
Date Date = (java.util.Date) (InMsgTstable[index][0]);
long Value3 = Date.getTime();
The date value i get is correct, though it drops the milliseconds value that is stored in my database.
I want to get this number of hours/minutes etc.. in milliseconds so i can put that number as a millisecond delay in a scheduler. However, this is giving me the wrong value in milliseconds.
Any tips?
If you are in control of the database table, I would change the column type to an integer type and simply store the timestamp in milliseconds as an integer value.
That will allow you to treat the value as the timestamp that
DateandCalendaruse natively without having to handle the conversions that databases perform on date and time columns.Edit
From your comment above I see that the value you get looks like the number of milliseconds since the start of the current day (which is by definition localtime, so beware of timezone values in the database.)
The date that you create using this timestamp is situated in Jan 1 1970, which is not what you want.
What you could do is to create a calendar object which defaults to “now”, back-up to the start of day and get that timestamp to add to the value you got from the database, something like (untested):
which should give you a
Dateobject representingmsgTableValuemilliseconds into the current day.