日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

Java黑皮书课后题第2章:*2.8(当前时间)程序清单2-7给出了显示当前格林尼治时间的程序。修改这个程序,提示用户输入相对于GMT的时区偏移量,显示在这个特定时区的时间

發(fā)布時(shí)間:2024/7/23 java 29 豆豆

*2.8(當(dāng)前時(shí)間)程序清單2-7給出了顯示當(dāng)前格林尼治時(shí)間的程序。修改這個(gè)程序,提示用戶輸入相對(duì)于GMT的時(shí)區(qū)偏移量,顯示在這個(gè)特定時(shí)區(qū)的時(shí)間

  • 題目
    • 題目描述
    • 運(yùn)行示例
    • 程序清單2-7(非本題代碼)+思路(注釋)
  • 代碼塊

題目

題目描述

*2.8(當(dāng)前時(shí)間)程序清單2-7給出了顯示當(dāng)前格林尼治時(shí)間的程序。修改這個(gè)程序,提示用戶輸入相對(duì)于GMT的時(shí)區(qū)偏移量,顯示在這個(gè)特定時(shí)區(qū)的時(shí)間

運(yùn)行示例

Enter the time zone offset to GMT: -5
The current time is 4:50:34

程序清單2-7(非本題代碼)+思路(注釋)

public class ShowCurrentTime {public static void main(String[] args) {// 2.8可以在這里獲取時(shí)區(qū)// Obtain the total milliseconds since midnight, Jan 1, 1970long totalMilliseconds = System.currentTimeMillis();// Obtain the total seconds since midnight, Jan 1, 1970long totalSeconds = totalMilliseconds / 1000;//2.8可以在這里將求出的秒數(shù)+時(shí)區(qū)和GMT時(shí)區(qū)的偏移(秒數(shù))// Compute the current second in the minute in the hourlong currentSecond = totalSeconds % 60;// Obtain the total minuteslong totalMinutes = totalSeconds / 60;// Compute the current minute in the hourlong currentMinute = totalMinutes % 60;// Obtain the total hourslong totalHours = totalMinutes / 60;// Compute the current hourlong currentHour = totalHours % 24;// Display resultsSystem.out.println("Current time is " + currentHour + ":"+ currentMinute + ":" + currentSecond + " GMT");} }

代碼塊

import java.util.Scanner;public class Test2_8 {public static void main(String[] args) {Scanner input = new Scanner(System.in);System.out.println("Enter the time zone offset to GMT:");int offset = input.nextInt();// Obtain the total milliseconds since midnight, Jan 1, 1970long totalMilliseconds = System.currentTimeMillis();// Obtain the total seconds since midnight, Jan 1, 1970long totalSeconds = totalMilliseconds / 1000;totalSeconds += offset * 60 * 60;// Compute the current second in the minute in the hourlong currentSecond = totalSeconds % 60;// Obtain the total minuteslong totalMinutes = totalSeconds / 60;// Compute the current minute in the hourlong currentMinute = totalMinutes % 60;// Obtain the total hourslong totalHours = totalMinutes / 60;// Compute the current hourlong currentHour = totalHours % 24;// Display resultsSystem.out.println("Current time is " + currentHour + ":"+ currentMinute + ":" + currentSecond + " GMT");} }

總結(jié)

以上是生活随笔為你收集整理的Java黑皮书课后题第2章:*2.8(当前时间)程序清单2-7给出了显示当前格林尼治时间的程序。修改这个程序,提示用户输入相对于GMT的时区偏移量,显示在这个特定时区的时间的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。