114-2 OOP B組 Week07 實習課練習 Problem1


Submit solution

Points: 100 (partial)
Time limit: 5.0s
Memory limit: 98M

Authors:
Problem type
Allowed languages
Java 19, Java 8

題目說明

在電腦系統中,時間常以Unix Timestamp(時間戳)表示,意指從 1970 年 1 月 1 日 00:00:00(UTC)起,所經過的秒數。

  • 其實Java有函式可以呼叫當下距離1970 年 1 月 1 日 00:00:00過了幾秒,但OJ沒辦法出,所以使用使用者自行輸入的方法。
      int sec = (int) (System.currentTimeMillis() / 1000);
    

請撰寫一個程式: 使用者輸入一個正整數N

表示從 1970-01-01 00:00:00 起經過的秒數。

請輸出該時間點所對應的日期(格式為 YYYY-MM-DD)。

注意事項

  1. 需自行處理:

    • 年份增加
    • 月份天數(28 / 29 / 30 / 31)
    • 閏年判斷
  2. 閏年規則:

    • 能被 4 整除且不能被 100 整除,或
    • 能被 400 整除
  3. 不需輸出時間(時、分、秒),只需輸出日期

  4. 建議使用Method拆解問題(例如):

    • static boolean isLeapYear(int year)
    • static int getDaysInMonth(int year, int month)

測資範圍

\[0 <= N <= 1775900000\]


範例輸入/輸出

範例輸入1

0

範例輸出1

1970-01-01

範例輸入2

31536000

範例輸出2

1971-01-01

範例輸入3

345678901

範例輸出3

1980-12-14

範例輸入4

789012345

範例輸出4

1995-01-02

範例輸入5

1023456789

範例輸出5

2002-06-07

Comments

There are no comments at the moment.