Subject | Re: [Firebird-Java] Timestamp Linux |
---|---|
Author | |
Post date | 2018-03-25T05:56:16Z |
Mark,
select and inserting CURRENT_TIMESTAMP and CURRENT_TIMESTAMP(3) gives ms.
Also inserting like this stores ms in Linux
insert into debit (CUSTOMER_ID, USER_ID, TOTSELLPRICE, REG_ID, RECEIPT_ID, timedebit) values (1,1,'100', 1, 1, '2018-03-25 12:02:30.784')
I should have explained better. The time is set with Calendar.getTimeInMillis().
Another observation, I wrote before that ms could be lost in serialization but this is not true because when I send data to remote windows server (Java 7. FB 2.5.3) the ms is there.
Here is the code:
public final void setTimestamp(long val, int nanos) {
if (setType != TIMESTAMP && setType != 0)
typeProblem(setType, TIMESTAMP, false);
type = Variant.TIMESTAMP;
if (timestampVal == null)
timestampVal = new Timestamp(System.currentTimeMillis());
long secs = val/TimeConst.MILLIS_PER_SECOND;
nanos += (int)((val%TimeConst.MILLIS_PER_SECOND) * (TimeConst.NANOS_PER_SECOND/TimeConst.MILLIS_PER_SECOND));
while (nanos < 0) {
nanos += TimeConst.NANOS_PER_SECOND;
--secs;
}
while (nanos > TimeConst.NANOS_PER_SECOND) {
nanos -= TimeConst.NANOS_PER_SECOND;
++secs;
}
timestampVal.setTime(secs*TimeConst.MILLIS_PER_SECOND);
timestampVal.setNanos(nanos);
}
select and inserting CURRENT_TIMESTAMP and CURRENT_TIMESTAMP(3) gives ms.
Also inserting like this stores ms in Linux
insert into debit (CUSTOMER_ID, USER_ID, TOTSELLPRICE, REG_ID, RECEIPT_ID, timedebit) values (1,1,'100', 1, 1, '2018-03-25 12:02:30.784')
I should have explained better. The time is set with Calendar.getTimeInMillis().
Another observation, I wrote before that ms could be lost in serialization but this is not true because when I send data to remote windows server (Java 7. FB 2.5.3) the ms is there.
Here is the code:
public final void setTimestamp(long val, int nanos) {
if (setType != TIMESTAMP && setType != 0)
typeProblem(setType, TIMESTAMP, false);
type = Variant.TIMESTAMP;
if (timestampVal == null)
timestampVal = new Timestamp(System.currentTimeMillis());
long secs = val/TimeConst.MILLIS_PER_SECOND;
nanos += (int)((val%TimeConst.MILLIS_PER_SECOND) * (TimeConst.NANOS_PER_SECOND/TimeConst.MILLIS_PER_SECOND));
while (nanos < 0) {
nanos += TimeConst.NANOS_PER_SECOND;
--secs;
}
while (nanos > TimeConst.NANOS_PER_SECOND) {
nanos -= TimeConst.NANOS_PER_SECOND;
++secs;
}
timestampVal.setTime(secs*TimeConst.MILLIS_PER_SECOND);
timestampVal.setNanos(nanos);
}