【发布时间】:2016-10-01 13:55:16
【问题描述】:
我正在尝试收集小时的分钟。这似乎在这个类中工作。现在我想在其他类中使用 intTime 进行一些计算。我如何返回 intTime。 在返回实例的属性时,我尝试使用相同的原则,但时间与我使用的任何对象都无关。 getIntTime 可行吗?
import java.text.SimpleDateFormat;
import java.util.*;
public class Time extends Database{
public Time(){
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat ("HH:mm:ss");
String stringTime = sdf.format (cal.getTime());
int intTime = 0;
stringTime = stringTime.substring(3,5); // retrieve the minutes (is recorded as string)
intTime = Integer.parseInt(stringTime);
}
public String getStringTime() {
return intTime;
}
public static void main (String[] args) {
}
}
【问题讨论】: