Forum Discussion

Adagio's avatar
Adagio
Frequent Contributor
7 years ago

convert 24 hr clock time to 12 hr clock time

Hello,

 

I've to convert the time stamps based on 24hr clock ro 12 hr clock.

For example - 1/4/2018 13:09:52   needs to be converted to 1/4/2018 1:09:52. 

 

Is there any built-in feature that I can utilize to do this conversion?

 

any help would be appreciated!

 

Thank you

abhi

  • shankar_r's avatar
    shankar_r
    7 years ago

    As tristaanogre said, you can those methods to generate whatever format you want,

     

    I'm just giving an example for your requirement,

     

    var dateValue = aqConvert.StrToDate("1/4/2018 13:09:52");
    Log.Message(aqConvert.DateTimeTpFormatStr(dateValue,%d-%b-%Y %I:%M:%S %p));
    
    01-Apr-2018 1:09:52 will get printed
    • shankar_r's avatar
      shankar_r
      Community Hero

      As tristaanogre said, you can those methods to generate whatever format you want,

       

      I'm just giving an example for your requirement,

       

      var dateValue = aqConvert.StrToDate("1/4/2018 13:09:52");
      Log.Message(aqConvert.DateTimeTpFormatStr(dateValue,%d-%b-%Y %I:%M:%S %p));
      
      01-Apr-2018 1:09:52 will get printed
    • Adagio's avatar
      Adagio
      Frequent Contributor

      Thank you Robert! aqConvert.StrToDateTime finction is very helpful.  Didn't know about it.

       

      here's the working code: 

       

      var dateValue = "1/4/2018 13:09:52" ;
      var formatStr = aqConvert.StrToDateTime(dateValue);
      Log.Message(formatStr);

      Thank you

      Abhi

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Actually, that will only work so long as the local settings on the machine running the test are set up for 12 hour time format.  If you want to explicitly set it to 12 hour format, regardless of the machine's local settings, you should use aqConvert.DateTimeToFormatStr as shankar_r noted