I'm converting a long number from server to local Datetime. The server time zone is GMT and we are converting to local Date time.
My question is there any simple method to do this as I'm pretty sure the below code is somewhat CPU expensive. Any simple method with fewer code like adding or subtracting numbers would be great.
My code - Java Code convert TimeZone
Long update_time = System.currentTimeMillis();
Date date = new Date(update_time);
Format format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
ZonedDateTime dateTime = ZonedDateTime.parse( format.format(date) + " GMT", formatter);
ZoneId zone = ZoneId.of("Asia/Kolkata");
ZoneId zone1 = ZoneId.systemDefault();
ZonedDateTime dt1 = dateTime.withZoneSameInstant(zone);
//ZonedDateTime utc = ZonedDateTime.parse( format.format(date) );
System.out.println("Original time: " + format.format(date));
System.out.println("Parsed time: " + dateTime.format(formatter) );
System.out.println("Local time: " + dt1.format(formatter) );