当前位置:   article > 正文

第六章第三十三题(当前日期和时间)(Current date and time)_希望变量current_da的值

希望变量current_da的值

**6.33(当前日期和时间)调用System.currentTimeMillis()返回从1970年1月1日0点开始至今为止的毫秒数。编写程序,显示当前日期和时间。

下面是运行示例:
Current date and time is May 16, 2012 10:34:23

**6.33(Current date and time) Invoking System.currentTimeMillis() returns the elapsed time in milliseconds since midnight of January 1, 1970. Write a program that displays the date and time.

Here is a sample run:
Current date and time is May 16, 2012 10:34:23

下面是参考答案代码:

public class CurrentDateAndTimeQuestion33 {
   
	public static void main(String[] args) {
   
		// Obtain the total milliseconds since midnight, Jan 1, 1970
		long totalMilliseconds = System.currentTimeMillis();

		// Obtain the total seconds since midnight, Jan 1, 1970
		int totalDays = (int) (totalMilliseconds / 1000 / 60 / 60 / 24);

		long totalSeconds = totalMilliseconds / 1000;

		// Compute the current second in the minute in the hour
		long currentSecond = totalSeconds % 60;
		// Obtain the total minutes
		long totalMinutes = totalSeconds / 60;

		// Compute the current minute in the hour
		long currentMinute 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/406769
推荐阅读
相关标签
  

闽ICP备14008679号