首页javalegacy_dateJava Data Type - 如何添加一分钟让所有方法都被调用

Java Data Type - 如何添加一分钟让所有方法都被调用

我们想知道如何添加一分钟让所有方法都被调用。
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
  public static void main(String[] args) {

    Test g = new Test();
    System.out.println("The time is now: " + g.currentTime());
    System.out.println("The time is now: " + g.currentTime());
    System.out.println("The time is now: " + g.currentTime());
    System.out.println("The time is now: " + g.currentTime());
  }
}

class Test {
  private int minutesToAdd = 0;
  private Calendar cal = Calendar.getInstance();
  SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

  public String currentTime() {
    cal.add(Calendar.MINUTE, minutesToAdd++);
    return sdf.format(cal.getTime());
  }
}