This article explains how to convert the system time based on the user timezone.
We have a scenario as shown below:
The system time zone is EST and the user timezone is PST. This screen shot is taken from SU3 transaction.
Now, we are going to write a sample ABAP report which shows time of the user according to the timezone set. Check the code snippet below to convert the time.
DATA ls_date TYPE sy-datlo. DATA ls_time TYPE sy-timlo. DATA timestamp TYPE timestamp. * Get the system timestamp GETTIMESTAMPFIELD timestamp. * Convert the system timestamp to user time CALLFUNCTION'IB_CONVERT_FROM_TIMESTAMP' EXPORTING
i_timestamp = timestamp
i_tzone = sy-zonlo IMPORTING
e_datlo = ls_date
e_timlo = ls_time. WRITE:/ 'System Date', sy-datum. WRITE:/ 'System Time', sy-uzeit. WRITE:/ 'User Date', ls_date. WRITE:/ 'User Time', ls_time.
The output of the program is shown below:
You can very well see the difference in time based on the timezone.
In systems where you can't find this standard FM, one can use below -
DATA timestamp TYPE timestamp.
* Get the system timestamp
GET TIME STAMP FIELD timestamp.
* Convert the system timestamp to user time
CONVERT TIME STAMP timestamp TIME ZONE sy-zonlo
INTO DATE ev_user_date TIME ev_user_time.