Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.hfreni.homework.Lesson2;
- import java.util.Scanner;
- public class Problem8_CurrentLocalTime
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Please Enter Time Zone: ");
- long timeZone = input.nextLong();
- // Basic clock
- 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;
- // Equations
- long currentLocalHour = currentHour + timeZone;
- long reset = currentLocalHour - 24;
- // Create an if loop to scan for time zones that are a day ahead. and to make time in standard
- if (currentLocalHour < 24)
- {
- if (currentLocalHour < 12)
- {
- System.out.println("The Current Time is " + currentLocalHour + ":" + currentMinute + ":" + currentSecond + "AM");
- }
- else
- {
- System.out.println("The Current Time is " + (currentLocalHour - 12) + ":" + currentMinute + ":" + currentSecond + "PM");
- }
- }
- else if (currentLocalHour > 24)
- {
- if(reset < 12)
- {
- System.out.println("The Current Time is " + reset + ":" + currentMinute + ":" + currentSecond + "AM");
- }
- else
- {
- System.out.println("The Current Time is " + (reset - 12)+ ":" + currentMinute + ":" + currentSecond + "PM");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement