java - 时钟机制
问题描述
我一直在尝试制作一个时区计算器,但从 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。提前谢谢大家!
解决方案
推荐阅读
- c - strtok_r 保存状态行为
- java - 您可以使用 session.execute 从 Datastax 驱动程序执行创建表吗?
- mysql - 字符串中的 MySQL 空格导致问题
- docker - 在gradle中生成dockerfile时设置环境变量?
- bash - 从文本文件读取的 Bash 脚本变量不起作用
- cron - Cron 作业创建数据库备份和邮件给我
- ionic-framework - Ionic Framework 3 错误:窗口重定向问题
- excel - 打印宏要么给我错误 1004 要么崩溃 excel
- javascript - 带有 jquery ajax 响应值的 Javascript 类属性设置器
- javascript - 如何在 jquery 中使用列标题名称获取表列数据