Another way is using the new java.time
-API in Java-8:
String result =
DateTimeFormatter.BASIC_ISO_DATE.format(
LocalDate.now(ZoneOffset.UTC).plusDays(7)
) + "T12:00:00+0000";
System.out.println(result); // 20161114T12:00:00+0000
Update due to your choice of timezone offset:
You tried to implicitly use the system timezone to determine the current local time but apply a fixed offset of UTC+0000. This is an inconsistent combination. If you apply such a zero offset then you should also determine the current date according to UTC+0000, not in your system timezone (ZoneId.systemDefault()
).
The proposal of editor @Nim
Alternatively - the string above may not have the correct offset:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HH:mm:ssZ");
String date = LocalDate.now().plusDays(7).atTime(12, 0).atZone(ZoneId.systemDefault()).format(formatter);
would yield the result:
20161114T12:00:00+0100
which is probably not what you want. I also try to avoid the expression LocalDate.now()
without any arguments because it hides the dependency on the system timezone.