convert C++ miiliseconds into Java Date
843829May 7 2007 — edited May 14 2007I am monitoring some events on C++ side and I get the time the event generated in milliseconds. ( DWORD evTime).
So I want to send this to a Java method in milliseconds, so that I can construct a Timestamp object.
c++ code:
// DWORD evTime is time in milliseconds
jenv->CallStaticVoidMethod(jcls, jmethID,(jlong) evTime);
java Code:
protected static void createTimeStamp(long timeAsMillisecs){
Timestamp ts = new Timestamp( timeAsMillisecs);
}
This doesn't work and I get weird dates in 1969..I believe it has to do with casting unsigned long to jlong on C++ side. Any ideas of what's wrong?
I also tried converting it into a time_t and then sending it as jlong to Java as below:
time_t iTime= evTime;
time_t rawtime = time(&iTime);
jenv->CallStaticVoidMethod(jcls, jmethID,(jlong) rawTime);
java side:
Timestamp ts = new Timestamp( timeAsMillisecs*1000);
(since time_t returns seconds, but I'm multiplying with 1000) .
This gives me correct time but it's only in seconds(eg: 2007-05-7 15:00:10.0) but I need the milliseconds. Any help is appreciated. Thanks.