如何从午夜到秒获得时间 [英] How to get the time since midnight in seconds
本文介绍了如何从午夜到秒获得时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
首先,这是一个我在Java 1课程中坚持的简单问题。这是一个静止的时间,我已经设置为8:49:12今天,我要弄清楚午夜过了多少秒,这到了午夜。 8小时49分12秒。
这是我现在的代码:
First off, this is a simple question that I'm stuck on in my Java 1 class. It's a static time that I set already as 8:49:12 "today" and I'm to figure out how many seconds past midnight and "to" midnight this represents. 8 hours, 49 minutes, and 12 seconds. Here is my code now:
hour = 8;
minute = 59;
second = 32;
System.out.println("The static time used for this program was: " + hour + ":" + minute + ":" + second);
我的问题是我不知道如何从 >和自午夜。
My issue is that I have no clue on how to get the time from and since midnight.
所以基本上输出需要:
Number of seconds since midnight:
Number of seconds to midnight:
后面的空格是秒。
谢谢,请解释原因,以及如何选择如何解决这个问题。我想学习:P
Thanks, and please explain why, and how you chose how to solve this. I want to learn :P
推荐答案
试试这个简单的数学:
System.out.println("Number of seconds since midnight:" +(second + (minute*60) + (hour*3600)));
System.out.println("Number of seconds to midnight:" +((60-second) + ((60-1-minute)*60) + (24-1-hour)*3600));
这篇关于如何从午夜到秒获得时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文