「Java」GregorianCalendarとDateの変換サンプル

書式
GregorianCalendar(int year, int month,int dayOfMonth)
使用例

package com.arkgame.study;

import java.text.DateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

public class GregoriancalendarDemo {

      public static void main(String[] args) {
            GregorianCalendar gc = new GregorianCalendar(2021, 1, 12);
            // Time -Date
            Date date = gc.getTime();

            // Format
            DateFormat df = DateFormat.getInstance();
            String resDate = df.format(date);
            System.out.println("結果1: " + resDate);

      }

}

実行結果
結果1: 21/02/12 0:00

Java

Posted by arkgame