0

I would like to know, how to get date of a certain time zone and update hours , mins and seconds of it. For example

if EST time now is 20230710 05:22:22 I want to update it to 20230710 01:25:00 and also get previous date and set time to 20230709 01:25:00

Using below i am getting EST time , but I am not able update the hour,mins and secs Please advise

TimeZone tz = TimeZone.getTimeZone("EST");
long utc = System.currentTimeMillis();
Date currentTime = new Date(utc);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
df.setTimeZone(tz);
String s = df.format(currentTime).replace("-", "");
coder
  • 231
  • 3
  • 11
  • 2
    Stop using outdated classes like `java.util.Date` and `SimpleDateformat`. Swith to the newer `java.time` API – Jens Jul 10 '23 at 12:25
  • Something like `ZonedDateTime then = ZonedDateTime.now(ZoneId.of("America/New_York")).withHour(1).withMinute(25).withSecond(0);` – g00se Jul 10 '23 at 13:38

0 Answers0