how to convert currentTimeMillis() to a Q timestamp?

http://download.oracle.com/javase/1.4.2/docs/api/java/lang/System.html#currentTimeMillis()

I was able to gather currentTimeMillis() and stick it into a Q table.

q)t2

ts_begin


1317614494097

1317614503813

1317614513677

1317614535603

1317614618160

1317614667602

1317614668603

1317614670208

1317614671808

1317614691443

I want to be able to do something like 

select (`timestamp$ts_begin) from t2

You would need to account for the difference in epoch for java (1970.01.01) and kdb (2000.01.01)

q)(2000.01.01-1970.01.01)*24*60*60*1000j

946684800000j

q)`timestamp$1317614494097j-(2000.01.01-1970.01.01)*24*60*60*1000j

2000.01.01D00:06:10.929694097

so you could do

select `timestamp$ts_begin-(2000.01.01-1970.01.01)*24*60*60*1000j) from t2

(judging from your numbers though, you seem to have millis after midnight?)

Something is not quite right… these should be within 3-4 minutes, not thousands of seconds.

q)select `timestamp$ts_begin-(2000.01.01-1970.01.01)*24*60*60*1000j from t2

ts_begin


2000.01.01D00:06:10.929694097

2000.01.01D00:06:10.929703813

2000.01.01D00:06:10.929713677

2000.01.01D00:06:10.929735603

2000.01.01D00:06:10.929818160

2000.01.01D00:06:10.929867602

2000.01.01D00:06:10.929868603

2000.01.01D00:06:10.929870208

2000.01.01D00:06:10.929871808

2000.01.01D00:06:10.929891443

should be datetime which is millis

timestamp is nanoseconds

? Attila

It’s still not working - sorry I just 

q)t2

ts_begin


1317614494097

1317614503813

1317614513677

1317614535603

1317614618160

1317614667602

1317614668603

1317614670208

1317614671808

1317614691443

q)`datetime$1317614494097j-(2000.01.01-1970.01.01)*24*60*60*1000j

**85.11.07T**:31:23.647

BTW: I will post this on code.kx.com for future reference.

To: personal-kdbplus@googlegroups.comX-Mailer: Apple Mail (2.1084)> q)`datetime$1317614494097j-(2000.01.01-1970.01.01)*24*60*60*1000j> **85.11.07T**:31:23.647q){“p”$1970.01.01D+1000000j*x}1317614494097j2011.10.03D04:01:34.097000000i.e. scale up to nanos, change epoch, and cast back

Thank you. I added this example to https://code.kx.com/trac/wiki/Reference/DollarSign

what i meant?when i said datetime is

?

q)f:{`datetime$(z%x)-y}[prd 24 60 60 1000j;(0^0ND)-1970.01.01]

?

q)f 1317614494097j

2011.10.03T04:01:34.097

?

but?using timestamp as Aaron’s suggests can save you from some headache with datetime (being float and all)
? Attila