1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter the time zone offset to GMT: "); 9 int offset = input.nextInt(); 10 11 input.close(); 12 13 long totalMilliseconds = System.currentTimeMillis(); 14 long totalSeconds = totalMilliseconds / 1000; 15 long currentSecond = totalSeconds % 60; 16 long totalMinutes = totalSeconds / 60; 17 long currentMinute = totalMinutes % 60; 18 long totalHours = totalMinutes / 60; 19 long currentHour = totalHours % 24; 20 21 long currentHourWithOffset = currentHour + offset; 22 23 if(currentHourWithOffset < 0) 24 currentHourWithOffset += 24; 25 else if(currentHourWithOffset > 23) 26 currentHourWithOffset -= 24; 27 28 System.out.println("The current time is " + currentHourWithOffset + ":" + currentMinute 29 + ":" + currentSecond); 30 } 31 }
时间: 2024-10-10 14:09:16