Forum Discussion

Behdad's avatar
Occasional Contributor
2 years ago

convert Bigdecimal to date


I receive JWT (Java token) in my APIS and it contain Expiration date as big decimal format (such as: 1691675508.431418)

I need to convent in to date & time format : yyyy mm dd HH MM SS Z

and use it in test case assertion

So I think i should use groovy script , but cant figure out how ?

OR if i can use any tools in ready api that do this conversion for me ?

I would be happy to share your experience on it with me

6 Replies

  • richie's avatar
    Community Hero
    Hey Behdad,

    Can't think of any native functionality in ReadyAPI that'll do this.

    You can use Java to convert bigDecimal dates to simpledate/datetime format.

    A stackoverflow shows you how to perform the conversion. -->

    BigDecimal bi = new BigDecimal("1096255084000");
    double decimal_timestamp = bi.doubleValue();
    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
    Calendar calendar = Calendar.getInstance();
    String date = formatter.format(calendar.getTime());

    I also found another option. -->

    String value = bigDecimal.toString();
    DateFormat format = new SimpleDateFormat("yyyyMMdd");
    format.setLenient(false); // to prevent things like February 30th
    Date date = format.parse(value);

    We can of course tweak the above to do your conversion, HOWEVER, i'm unsure how to pick up a value from a JWT.

    Think you might need a real expert like KarelHusa o4 ChrisAdams, etc.

    Hope this gives you a start off point,



    • Behdad's avatar
      Occasional Contributor

      Many Thanks Rich 

      I am not expert in scripting , but i try to use your suggestions  as Groovy script in ReadyAPI

      find two issue

      1- Cant find your suggested methods in java.util.Calendar

      2- When i try to convert big decimal value i receive form JWT token using formatter :

      any value i receive it always convert to  1970-01-20 with different times ?!



      BigDecimal BD1 = new BigDecimal("1669906025.870166");
      BigDecimal BD2 = new BigDecimal("1670337568.956325");
      BigDecimal BD3 = new BigDecimal("1670338168.956311");
      double decimal_timestamp = BD1.doubleValue();
      SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS")
      formatter.setTimeZone(TimeZone.getTimeZone("UTC")); 'formatter BD1 ' + formatter.format(BD1) 'formatter BD2 ' + formatter.format(BD2) 'formatter BD3 ' + formatter.format(BD3)


      ******* log


      formatter BD1 20/01/1970 07:51:46.025
      formatter BD2 20/01/1970 07:58:57.568
      formatter BD3 20/01/1970 07:58:58.168


      So do you have any suggestion ?



  • nmrao's avatar
    Champion Level 3

    Curious, how the expiry date is going to be used?

    • Behdad's avatar
      Occasional Contributor

      Hi Rao
      As part of JWT  body It control validity time of Token Authentication.

      So i need to control  validity time & expiration of different token types.

      In this case i need to parse token with such format i receive :






  • nmrao's avatar
    Champion Level 3

    Thank you Behdad.

    So, do you check the time each time a request is going to be send?


    Does your response contain refresh_token?

    • Behdad's avatar
      Occasional Contributor

      U R wellcome

      Of course

      Refresh token is another endpoint of authentication package.

      But as QA test , we need to have test cases to control and double check all details.


      So in this case do you havre any suggestion to parse/convert timestamp values ?