ときに私のコード次の出力(JavaへのDR梁はじめ、10編から取られた、第03章 - 。。選択)のJava - 現在の時刻(GMT)の分で0を追加
/*
(Current time) Listing 2.7, ShowCurrentTime.java, gives a program that displays
the current time in GMT. Revise the program so that it prompts the user to enter
the time zone offset to GMT and displays the time in the specified time zone.
*/
import java.util.Scanner;
public class Ex_03_08 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the time zone (GMT): ");
int gmt = 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 % 24;
currentHour = currentHour + gmt;
System.out.println("The current time is " + currentHour + ":"
+ currentMinute + ":" + currentSecond);
input.close();
}
}
出力は
Enter the time zone (GMT): 1
The current time is 11:2:31
でどのように私は、ディスプレイの代わりに11:02:31?
ありがとうせることができます。