首页 > 解决方案 > 时钟机制

问题描述

我一直在尝试制作一个时区计算器,但从 0h 到 24h 有问题,反之亦然。这是我的代码:

import java.util.Scanner; //this is for something else in the main method
import java.time.Clock;

public class TmzCalc extends Thread
{

public static void main(String args[])
{
//skipping some useless code
TmzCalc.hst(int hr); //the integer is declared inside main, and used by the 
hst method
}

public static void hst(int hr)
{
int x = hr - 10;
if(hr < 0){
   hr = 24;
};
     System.out.println("Honolulu-HST :: " + x);
}

现在问题来了:如果我说 hr 是 2,那么它将打印 -8,我实际上希望它打印的是 16。提前谢谢大家!

标签: javatimezonelogicclock

解决方案


推荐阅读