0

I am using Ready API and I was wondering how to convert a date value that is fetched from Oracle SQL Database from a JDBC connection which is stored in an XML Holder inside a Script Assertion and then using the same to assert with a timestamp value fetched from an API Response.

Ex; The Value obtained from the Database looks like

2015-7-8 17:40:44. 715000000

And the date from the API Response looks like

1436377244715

Question is how do I convert the Date got from the Database or from the Response to make it assertible

subby
  • 71
  • 6

1 Answers1

0

If you want to convert your date 1436377244715 date then you can use :

Date d = new Date(Long.parseLong("1436377244715"));

The second you can get your Date fro; 2015-7-8 17:40:44. 715000000 like this :

String str = "2015-7-8 17:40:44. 715000000";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss. SSS");

Date date = format.parse(str);
System.out.println(date);

So to compare the two dates you can use :

//convert the date from the API Response
Date date1 = new Date(Long.parseLong("1436377244715"));

//convert the date obtains from DATABASE
String str = "2015-7-8 17:40:44. 715000000";
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-M-d HH:mm:ss. SSS");
Date date2 = format2.parse(str);

System.out.println(date1);
System.out.println(date2);

//check if the two dates are equal or not
if (date1.equals(date2)) {
    System.out.println("CORRECT");
} else {
    System.out.println("NOT CORRECT");
}

This will gives you :

Wed Jul 08 18:40:44 WAT 2015
Fri Jul 17 00:17:24 WAT 2015
NOT CORRECT
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
  • Thank you but in reality the values that i provided in my question are equal after conversion. So why are they not getting parsed properly? I mean i need to make it comparable which means positive assertions – subby Apr 10 '17 at 10:30
  • If you want to cross cheeck you could use this site https://www.epochconverter.com/ – subby Apr 10 '17 at 10:32
  • @subby `1436377244715 ===== 2015-7-8 18:40:44. 715` and not `2015-7-8 17:40:44. 715` so check you are using the correct dates – Youcef LAIDANI Apr 10 '17 at 10:38
  • But when i use the above site, it shows me the one that I provided – subby Apr 10 '17 at 10:45
  • The timezone must be GMT..if it helps – subby Apr 10 '17 at 10:46
  • can i see what dates you try @subby – Youcef LAIDANI Apr 10 '17 at 10:46
  • Here are some sample dates where the left ones are fetched from the Database and the right ones(timestamps) are from the Response of the API – subby Apr 10 '17 at 10:59
  • 2015-7-8 17:40:44. 715000000 -------> 1436377244715 | 2015-7-31 15:10:8. 858358000 -------> 1438355408858 | 2016-8-18 14:24:21. 307701000 ------> 1471530261307 – subby Apr 10 '17 at 10:59
  • I want to convert them to validate them as equal – subby Apr 10 '17 at 11:01