共計 431 個字符,預計需要花費 2 分鐘才能閱讀完成。
要獲取當前年月日,可以使用 Java 中的 LocalDate
類來實現。以下是一個示例代碼:
import java.time.LocalDate;
public class Main {public static void main(String[] args) {// 獲取當前日期
LocalDate currentDate = LocalDate.now();
// 獲取當前年份
int year = currentDate.getYear();
// 獲取當前月份
int month = currentDate.getMonthValue();
// 獲取當前日期
int day = currentDate.getDayOfMonth();
System.out.println(" 當前年份:" + year);
System.out.println(" 當前月份:" + month);
System.out.println(" 當前日期:" + day);
}
}
運行以上代碼,將輸出當前的年份、月份和日期。
丸趣 TV 網 – 提供最優質的資源集合!
正文完