0

I have scheduler where it runs every 30 mins and I need to generate 30 mins(configurable) time difference in date with this pattern yyyy-MM-dd'T'HH:mm:ss.SSS'Z'.

For example

start_date=2020-01-27T08:00:00.000z and end_date=2020-01-27T08:30:00.000z
start_date=2020-01-27T08:30:00.000z and end_date=2020-01-27T09:00:00.000z
start_date=2020-01-27T09:00:00.000z and end_date=2020-01-27T09:30:00.000z
start_date=2020-01-27T09:30:00.000z and end_date=2020-01-27T10:00:00.000z

How to generate with this pattern in Java 8 ?

VG P
  • 337
  • 3
  • 9
  • So, you have two basic problems. Add time to another time value and, formatting said result. Both questions are commonly asked and have a large number of answers not just on SO, but also the web generally. This then raises the question of, what issue(s) are you having solving these problems – MadProgrammer Feb 02 '20 at 23:30
  • 1
    While I'm pointing to `LocalDateTime` as a starting point, you might also consider `ZonedDateTime` – MadProgrammer Feb 02 '20 at 23:33
  • Search for `ScheduledExecutorService`, `Instant`, and `Duration` classes. Read the Oracle tutorials on [the Executors framework](https://docs.oracle.com/javase/tutorial/essential/concurrency/executors.html) and [the *java.time* framework](https://docs.oracle.com/javase/tutorial/datetime/TOC.html). Learn about [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601). P.S. Never put quotes around the `Z` in a date-time formatting pattern because you would be ignoring vital information. – Basil Bourque Feb 03 '20 at 05:33
  • This is an API call where I need to pass it as query parameter to fetch data for 30 mins or 60 mins based on configuration using start and end date. Is there any way to add 30 mins or 40 mins and generate date time based on this format 2020-01-27T08:00:00.000z – VG P Feb 04 '20 at 14:24

0 Answers0