Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

What is the ABAP equivalent for java's System.currentTimeMillis()

Former Member
0 Likes
758

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
629

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 ) ).

2 REPLIES 2
Read only

Former Member
0 Likes
630

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 ) ).

Read only

Former Member
0 Likes
629

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.