显示世界时间 GMT GMT+N

import java.util.*;
class Main {

     public static void main(String []args) {
      Scanner input = new Scanner(System.in);
      System.out.print("Enter the time zone offset to GMT:");
       int timeZone = input.nextInt();
       // Obtain the total milliseconds since midnight, Jan 1,1970
		  long totalMilliseconds = System.currentTimeMillis();
    		
		  //Obtain the total seconds since midnight,Jan 1,1970
		  long totalSeconds = totalMilliseconds / 1000;
    		
		  //Compute the current second in the minute in the hour
		  long currentSecond = totalSeconds % 60;
    		
		  //Obtain the total minutes
		  long totalMinutes = totalSeconds / 60;
    		
		  //Compute the current minute in the hour
		  long currentMinute = totalMinutes % 60;
    		
		  //Obtain the total hours
		  long totalHours = totalMinutes / 60;
    		
		  //Compue the current hour
		  long currentHour = totalHours % 24;
    		
		
		  //GMT + N
		  long newTotalHour = totalHours + timeZone;
		  long newCurrentHour = newTotalHour % 24;
    	if(timeZone > 0){
        System.out.println("Current time is " + newCurrentHour + ":"
						   + currentMinute + ":" + currentSecond + " GMT+" + timeZone);    
      }else if(timeZone < 0){
        System.out.println("Current time is " + newCurrentHour + ":"
						   + currentMinute + ":" + currentSecond + " GMT" + timeZone);    
      }else if(timeZone == 0){
		    System.out.println("Current time is " + currentHour + ":"
						   + currentMinute + ":" + currentSecond + " GMT");
      }
	}
}
posted @ 2022-05-08 13:17  Scenery_Shelley  阅读(55)  评论(0)    收藏  举报