Reputation: 499
I have so simple question. Although I spent couple of hours, I could not find the solution of the problem but I am sure that there is a small trick that I do not know.
if(selectJob.getType() == 'G'){
long tardy = Long.parseLong(offSetValue);
Timestamp gleichzeitig = new Timestamp(dateBegin.getTime()+ tardy);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String simulDate = simpleDateFormat.format(gleichzeitig);
atnajsonJobLine.add(simulDate);
}
tardy number and date_begin are taken from the user via GUI. Although in debugged mode, I saw that I managed to add tardy number into the begin date but in the console it is simply written begin date.
//Expected output:
beginDate: 13:10:00 tardy: 10
simulDate : 13:10:10
//Actual: 13:10:00
Could someone help me? Advance thanks.
Upvotes: 0
Views: 77
Reputation: 2433
You are adding 10 milliseconds. Try this ->
if(selectJob.getType() == 'G'){
long tardy = Long.parseLong(OffSetValue);
Timestamp gleichzeitig = new Timestamp(date_begin.getTime() + tardy * 1000);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String SimulDate = simpleDateFormat.format(gleichzeitig);
atnajsonJobLine.add(SimulDate);
}
Upvotes: 1
Reputation: 26926
Timestamp
is based on milliseconds.
Adding 10 will result in the same seconds (and 10 milliseconds more).
If you print milliseconds you can see.
Try to add 10 * 1000 instead of 10.
Upvotes: 2