Forum Discussion

SK07's avatar
6 years ago

Groovy: compare the date format

I want to compare the date from json 1 & json 2 and display if its match or not in this array.

Json1 : {"prods": [{"Item":"11","date": "2018-08-08"}
Json2: {"prods": [{"Item":"12","date": 1533700800000}

4 Replies

  • Lucian's avatar
    Community Hero

    This is the code that allows you to compare the dates:


    import java.text.SimpleDateFormat
    // Get timestamp
    def timestamp = 1533700800000
    // Set a date using the timestamp
    def date = new Date( timestamp )
    // Create a date format as desired
    SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" )
    // Get the other date
    secondDate = "2018-08-08"
    assert dateFormat.format( date ).equals(secondDate) 

    Let me know if you also need help with the JSON extraction. I am a little busy now so I can't promise anything though.

    • SK07's avatar

      Lucian, I wanted to read the date(milliseconds) from each array of Json1(convert this date to yyyy-mm-dd)

      and compare it with Json2 date (yyyy-mm-dd) of each array.

      • Lucian's avatar
        Community Hero
        Ok, I will try to also help you with the Json extraction the next week. I am very busy though...