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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

第三章第三十题(当前时间)(Current time)

發布時間:2024/1/1 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第三章第三十题(当前时间)(Current time) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第三章第三十題(當前時間)(Current time)

  • *3.30(當前時間)修改編程練習題2.8,以12小時時鐘制顯示小時數。
    下面是一個運行示例:
    Enter the time zone offset to GMT:-5
    The current time is 4:50:34 AM

    *3.30(Current time) Revise Programming Exercise 2.8 to display the hour using a 12-hour clock.
    Here is a sample run:
    Enter the time zone offset to GMT:-5
    The current time is 4:50:34 AM

  • 參考代碼:

package chapter03;import java.util.Scanner;public class Code_30 {public static void main(String[] args) {int ZoneOffset;long CurrHours,CurrMinutes,CurrSeconds;long CurrentMilliSeconds;CurrentMilliSeconds = System.currentTimeMillis();CurrSeconds = CurrentMilliSeconds / 1000 % 60;CurrMinutes = CurrentMilliSeconds / 1000 / 60 % 60;CurrHours = CurrentMilliSeconds / 1000 / 60 / 60 % 24;System.out.print("Enter the time zone offset to GMT : ");Scanner ZoneOffsetInput = new Scanner(System.in);ZoneOffset = ZoneOffsetInput.nextInt();CurrHours = (CurrHours + ZoneOffset + 24) % 24;if(CurrHours <= 12)System.out.println("The current time is "+ CurrHours + ":" + CurrMinutes + ":" + CurrSeconds + " AM");else{CurrHours %= 12;System.out.println("The current time is "+ CurrHours + ":" + CurrMinutes + ":" + CurrSeconds + " PM");}ZoneOffsetInput.close();} }
  • 結果顯示:
Enter the time zone offset to GMT : 8 The current time is 11:15:40 AMProcess finished with exit code 0

總結

以上是生活随笔為你收集整理的第三章第三十题(当前时间)(Current time)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。