Current Time ke GMT

Selamat pagi semuanya, alhamdulillah kita masih diberi kesehatan oleh Tuhan Yang Maha Esa. kali saya akan membagikan cara merubah current time ke GMT.

Selamat mencoba, semoga berhasil, . .

import java.util.Scanner;

public class CurrentTimeToGMT {

public static void main(String[] iriahus) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);

long currentTime = System.currentTimeMillis();
long totalSecond = currentTime / 1000;
long seconds = totalSecond % 60;
long minutes = totalSecond / 60 % 60;
long hours = totalSecond / 3600 % 24;

if (hours < 10 && minutes < 10 && seconds < 10) {
System.out.println("The current time is 0" + hours + ":0" + minutes +
":0" + seconds + " GMT");
}
else if (hours < 10 && minutes < 10 && seconds >= 10) {
System.out.println("The current time is 0" + hours + ":0" + minutes +
":" + seconds + " GMT");
}
else if (hours < 10 && minutes >= 10 && seconds < 10) {
System.out.println("The current time is 0" + hours + ":" + minutes +
":0" + seconds + " GMT");
}
else if (hours >= 10 && minutes < 10 && seconds < 10) {
System.out.println("The current time is " + hours + ":0" + minutes +
":0" + seconds + " GMT");
}
else if (hours < 10 && minutes >= 10 && seconds >= 10) {
System.out.println("The current time is 0" + hours + ":" + minutes +
":" + seconds + " GMT");
}
else if (hours >= 10 && minutes < 10 && seconds >= 10) {
System.out.println("The current time is " + hours + ":0" + minutes +
":" + seconds + " GMT");
}
else if (hours >= 10 && minutes >= 10 && seconds < 10) {
System.out.println("The current time is " + hours + ":0" + minutes +
":0" + seconds + " GMT");
} else {
System.out.println("The current time is " + hours + ":" + minutes +
":" + seconds + " GMT");
}

System.out.print("Enter the time zone offset to GMT: ");
int offset = s.nextInt();

if (offset < -12 || offset > 12) {
System.out.println("Invalid input");
System.exit(offset);
}
else if ((hours + offset) > 23) {
System.out.println("The offset time is " + (hours + offset - 24) +
":" + minutes + ":" + seconds);
}
else if ((hours + offset) < 0) {
System.out.println("The offset time is " + (hours + offset + 24) +
":" + minutes + ":" + seconds);
} else {
System.out.println("The offset time is " + (hours + offset) +
":" + minutes + ":" + seconds);
}
}

}

Thank for visiting. Semoga bermanfaat, .

Subscribe to receive free email updates:

0 Response to "Current Time ke GMT"

Post a Comment