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

convert time between internal and external

wanglin_hu
Product and Topic Expert
Product and Topic Expert
16,098

hi

I want to convert time between internal and external by parameter 'XUTIMEFM'. is there any good method? ps: 'cl_abap_timefm' have method 'conv_time_int_to_ext', but it does not match my requirement , i need convert time by date element 'XUTIMEFM'. thanks

1 ACCEPTED SOLUTION
Read only

0 Likes
6,571

Try this?

CONVERT_DATE_TO_EXTERNAL

CONVERT_DATE_TO_INTERNAL

7 REPLIES 7
Read only

Former Member
0 Likes
6,571

Hi,

Could you please elaborate on the parameter mentioned? Is it a time zone?

Just check the below FMs.

CONVERT_DATE_TO_EXTERNAL

CONVERT_DATE_TO_INTERNAL

PCA_CONVERT_DATE_EXTERNAL

PCA_CONVERT_DATE_INTERNAL

If the parameter is time zone you can use the below syntax.

CONVERT TIME STAMP time_stamp TIME ZONE tz

INTO [DATE dat] [TIME tim]

[DAYLIGHT SAVING TIME dst].

Read only

wanglin_hu
Product and Topic Expert
Product and Topic Expert
0 Likes
6,571

in T-CODE su01, user can set defaults on time format. this field uses data element 'XUTIMEFM'. i just want to convert time by import parameter type 'XUTIMEFM'. this data element is not time zone and is for time fromat

because user can have different choise on time format, so i can't use 'write environment time format'.

Edited by: Wang Lin Hu on Sep 19, 2011 9:24 AM

Read only

0 Likes
6,572

Try this?

CONVERT_DATE_TO_EXTERNAL

CONVERT_DATE_TO_INTERNAL

Read only

wanglin_hu
Product and Topic Expert
Product and Topic Expert
0 Likes
6,571

i want time convertion not date convertion, but thanks

Read only

0 Likes
6,571

hi,

try this code and after tests embedd it into your classes or subroutine:

...

REPORT  Z_TIME_CONVERT_LLM.


PARAMETERS: p_time     type tims,
            P_period(2) type c, "PM, pm, AM, am.
            p_format    type XUTIMEFM.


START-OF-SELECTION.

data: g_output_time TYPE tims,
      g_hour(2)     TYPE n,
      g_minuts(2)   TYPE n,
      g_seconds(2)  type n,
      c_code(2)     type c.


 g_hour    = p_time(2).
 g_minuts  = p_time+2(2).
 g_seconds = p_time+4(2).

case p_format.

  when 0.

           if g_hour = '00' and p_period = 'PM' . add 12 to g_hour . ENDIF.

  when 1 or 2.

          if g_hour = '00' and ( p_period = 'PM' or p_period = 'pm' ).
                  add 12 to g_hour . ENDIF.
          if g_hour  > 12  and  ( p_period = 'PM' or p_period = 'pm' ).
             sUBTRACT 12 FROM g_hour . ENDIF.

  when 3 or 4.

          if g_hour  ge 12  and  ( p_period = 'PM' or p_period = 'pm' ).
             sUBTRACT 12 FROM g_hour . ENDIF.

ENDCASE.

g_output_time(2)   = g_hour.
g_output_time+2(2) = g_minuts.
g_output_time+4(2) = g_seconds.



WRITE: g_output_time, ' ', p_period .







Read only

Former Member
6,571

Hi,

You can try FM CONVERT_TIME_INPUT / OUTPUT.

Read only

juergen_ette
Product and Topic Expert
Product and Topic Expert
0 Likes
6,571

Hi ,

please have a look to the services provided in package SABP_CONVERT.

For you are the services of CL_ABAP_TIMEFM interesting especially CL_ABAP_TIMEFM=>CONV_TIME_EXT_TO_INT/CONV_TIME_INT_TO_EXT

Furthermore to this classes AUnits are attached demonstrating how to use these methods.

This thread is quite old, but may be interesting for people working with web search engines.

Regards, Jürgen