0

I have the following code now. This is basically called to get all the summary (in this case summary about some tests). Timezone is set to UTC currently. I want to get all data based on the local time zone. Please provide me any idea to do this?

public List<TestEntity> getAllTestSummary(String status) {
    Timestamp timestampEnd = new Timestamp(System.currentTimeMillis());
    long tenAgo = System.currentTimeMillis() - TEN_MINUTES;
    Timestamp timestampStart = new Timestamp(tenAgo);
    String TSPATTERN = "yyyy-MM-dd HH:mm:ss";
    DateFormat df = DateFormat.getDateTimeInstance();
    df = new SimpleDateFormat(TSPATTERN);
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    timestampStart = Timestamp.valueOf(df.format(timestampStart).toString());
    timestampEnd = Timestamp.valueOf(df.format(timestampEnd).toString());
    return testRepository.findByStatusIgnoreCase(status);
}

I tried using joda but didn't get the desired output.

Vy Do
  • 46,709
  • 59
  • 215
  • 313
Akhil Suseelan
  • 217
  • 1
  • 5
  • 25
  • Does this answer your question? [Convert UTC to LocalDateTime in Joda?](https://stackoverflow.com/questions/25977197/convert-utc-to-localdatetime-in-joda) – Curiosa Globunznik Feb 15 '20 at 08:29
  • @güriösä It is useful. But how do I convert dynamically based on JVM timezone? – Akhil Suseelan Feb 15 '20 at 10:48
  • I didn’t get it, sorry. How are you passing the times to your summary getting service? And how is “the last 10 minutes in JVM time zone” different from “the last 10 minutes in UTC”? Surely they are still the same 10 minutes? – Ole V.V. Feb 15 '20 at 16:58
  • 1
    Did you consider java.time, the modern Java date and time API? The folks developing Joda-Time went on to develop java.time, so it’s considered the improved and more modern replacement. – Ole V.V. Feb 15 '20 at 17:01

0 Answers0