ABAP UNIX timestamp
Getting UNIX/Epoch timestamp from the UI client is not reliable. Timestamps are generated based on the time set on the device. It is much better to let the ABAP application server create timestamps. To my knowledge, it is not possible to to generate a UNIX/Epoch timestamp in any SAP delivered method or function.
This little static method generates a timestamp that equals number of milliseconds since 01.01.1970.
class zcl_epoch definition
public
final
create public .
public section.
class-methods get_time
returning
value(value) type numc13 .
protected section.
private section.
endclass.
class zcl_epoch implementation.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_EPOCH=>GET_TIME
* +-------------------------------------------------------------------------------------------------+
* | [<-()] VALUE TYPE NUMC13
* +--------------------------------------------------------------------------------------</SIGNATURE>
method get_time.
data time type tzntstmpl.
data str1 type string.
data str2 type string.
data tstmp1 type p.
data tstmp2 type p.
data secs type tzntstmpl.
get time stamp field time.
tstmp1 = time.
tstmp2 = '19700101000000'.
try.
secs = cl_abap_tstmp=>subtract(
tstmp1 = tstmp1
tstmp2 = tstmp2
).
catch cx_parameter_invalid_range .
catch cx_parameter_invalid_type .
endtry.
str1 = secs.
str2 = time.
value = str1(10) && str2+15(3).
endmethod.
endclass.
Thanks for sharing.
Actually, there is also SAP (standard?) method hiding out there:
cl_pco_utility=>convert_java_timestamp_to_abap
You may you use it the following:
Hi,
How about this?
Best Regards,
Ashok.