Write a Java program that prints the current time in GMT
- برمجة جافا
- برمجة
- 2021-05-01
- razanmazen8711884270
الأجوبة
import java.util.Scanner;
public class Exercise5 {
public static void main(String[] Strings) {
Scanner input = new Scanner(System.in);
System.out.print("Input the time zone offset to GMT: ");
long timeZoneChange = input.nextInt();
long totalMilliseconds = System.currentTimeMillis();
long totalSeconds = totalMilliseconds / 1000;
long currentSecond = totalSeconds % 60;
long totalMinutes = totalSeconds / 60;
long currentMinute = totalMinutes % 60;
long totalHours = totalMinutes / 60;
long currentHour = ((totalHours + timeZoneChange) % 24);
System.out.println("Current time is " + currentHour + ":" + currentMinute + ":" + currentSecond);
}
}
Sample Output:
Input the time zone offset to GMT: 256 Current time is 5:7:51
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال