TimeStamp in java

Viewed 48

I am trying to convert a date after fetching from a database, converting it to epoch and asserting from API response. This is running fine in local, but failing on Jenkins, any idea why? The database gives the date in UTC.

String Repeated = IntStream.range(0, length).mapToObj(i -> "S").collect(Collectors.joining(""));
ZonedDateTime zonedDateTime = ZonedDateTime.parse(
                getEntries.get("created_at").toString() + ZoneId.of("Asia/Kolkata"),
                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss." + Repeated +"zzz")
        ).withZoneSameInstant(ZoneId.of("Asia/Kolkata"));
long epoch = zonedDateTime.toInstant().toEpochMilli();

I used repeated since the number of digits after the decimal is variable ,so I am counting it and sending it there.

So this is the error which is thrown, basically I am guessing the timestamp conversion is wrong. TimeStamp Does not Match in API and DB expected [1663897726915] but found [1663917526915]. The timestamp is stored as text in the database, and in the format 1970-01-01 01:01:29.401 +0630.

0 Answers
Related