‎2005 Feb 26 1:09 AM
Hi ABAP experts,
Anybody know what is the ABAP equivalent command for java System.currentTimeMillis() ?
I can only find "GET TIME STAMP FIELD" which gives just the date and time in a numeric format. But i really need ABAP to return the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
Thanxs
Fredrick
‎2005 Feb 26 1:39 AM
Since ABAP supports date arithmetic you could try the following:
GET TIME.
integer =
( ( sy-datum - '19700101' ) * ( millisecs in a day ) )
+
( sy-uzeit(2) * ( millisecs in an hour ) )
+
( sy-uzeit+2(2) * ( millisecs in a minute ) )
+
( sy-uzeit+4(2) * ( millisecs in a second ) ).
‎2005 Feb 26 1:39 AM
Since ABAP supports date arithmetic you could try the following:
GET TIME.
integer =
( ( sy-datum - '19700101' ) * ( millisecs in a day ) )
+
( sy-uzeit(2) * ( millisecs in an hour ) )
+
( sy-uzeit+2(2) * ( millisecs in a minute ) )
+
( sy-uzeit+4(2) * ( millisecs in a second ) ).
‎2005 Feb 28 7:32 PM
Thanks for you tip! In the end, i still need to use GET TIME to ensure the time is in UTC. Here is my code.
<b>FUNCTION CURRENT_TIME_MILLIS.
*"----
""Local interface:
*" EXPORTING
*" REFERENCE(E_CURRENT_MILLIS) TYPE NUMC15
*"----
</b> DATA: date_1970 TYPE DATS value '19700101',
millis_in_day TYPE NUMC15 value '86400000',
millis_in_hour TYPE NUMC15 value '3600000',
millis_in_min TYPE NUMC15 value '60000',
millis_in_sec TYPE NUMC15 value '1000',
current_date TYPE DATS,
current_ts TYPE timestampl,
current_ts_s(22),
sec_fraction TYPE F.
GET TIME STAMP FIELD current_ts.
current_ts_s = current_ts.
current_date = current_ts_s(8).
sec_fraction = current_ts_s+14(8).
e_current_millis = ( current_date - date_1970 ) * millis_in_day +
current_ts_s+8(2) * millis_in_hour +
current_ts_s+10(2) * millis_in_min +
current_ts_s+12(2) * millis_in_sec +
sec_fraction * millis_in_sec.
ENDFUNCTION.