Advertisement
Guest User

GNAA

a guest
Oct 1st, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. package com.hfreni.homework.Lesson2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Problem8_CurrentLocalTime
  6. {
  7.     public static void main(String[] args)
  8.     {
  9.         Scanner input = new Scanner(System.in);
  10.  
  11.         System.out.println("Please Enter Time Zone: ");
  12.         long timeZone = input.nextLong();
  13.  
  14.         // Basic clock
  15.         long totalMilliseconds = System.currentTimeMillis();
  16.         long totalSeconds = totalMilliseconds/1000;
  17.         long currentSecond = totalSeconds % 60;
  18.         long totalMinutes = totalSeconds / 60;
  19.         long currentMinute = totalMinutes % 60;
  20.         long totalHours = totalMinutes / 60;
  21.         long currentHour = totalHours % 24;
  22.  
  23.         // Equations
  24.         long currentLocalHour = currentHour + timeZone;
  25.         long reset = currentLocalHour - 24;
  26.  
  27.         // Create an if loop to scan for time zones that are a day ahead. and to make time in standard
  28.         if (currentLocalHour < 24)
  29.         {
  30.             if (currentLocalHour < 12)
  31.             {
  32.                 System.out.println("The Current Time is " + currentLocalHour + ":" + currentMinute + ":" + currentSecond + "AM");
  33.             }
  34.             else
  35.             {
  36.                 System.out.println("The Current Time is " + (currentLocalHour - 12) + ":" + currentMinute + ":" + currentSecond + "PM");
  37.             }
  38.         }
  39.         else if (currentLocalHour > 24)
  40.         {
  41.             if(reset < 12)
  42.             {
  43.                 System.out.println("The Current Time is " + reset + ":" + currentMinute + ":" + currentSecond + "AM");
  44.             }
  45.             else
  46.             {
  47.                 System.out.println("The Current Time is " + (reset - 12)+ ":" + currentMinute + ":" + currentSecond + "PM");
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement