「Java」java.util.Calendarで現在の年月月を取得するサンプルコード

サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study;
import java.util.Calendar;
public class CalendarDemo {
public static void main(String[] args) {
Calendar cd = Calendar.getInstance();
int year = cd.get(Calendar.YEAR);
int month = cd.get(Calendar.MONTH) + 1;
int day = cd.get(Calendar.DATE);
System.out.println("本日:" + year + "年" + month + "月" + day + "日");
}
}
package com.arkgame.study; import java.util.Calendar; public class CalendarDemo { public static void main(String[] args) { Calendar cd = Calendar.getInstance(); int year = cd.get(Calendar.YEAR); int month = cd.get(Calendar.MONTH) + 1; int day = cd.get(Calendar.DATE); System.out.println("本日:" + year + "年" + month + "月" + day + "日"); } }
package com.arkgame.study;

import java.util.Calendar;

public class CalendarDemo {

      public static void main(String[] args) {
            Calendar cd = Calendar.getInstance();
            int year = cd.get(Calendar.YEAR);
            int month = cd.get(Calendar.MONTH) + 1;
            int day = cd.get(Calendar.DATE);

            System.out.println("本日:" + year + "年" + month + "月" + day + "日");
      }

}

結果
本日:2020年6月30日

Java

Posted by arkgame