Date类有一个getTime()可以换回秒数,例如:
public class DateToSecond
{
public static void main(String[] args)
{
Date date = new Date(System.currentTimeMillis());
System.out.println(date.getTime());
}
}
自己写个算法算就是了 System.getCurrentTime()是获取当前时间 距 1970-1-1-00:00:00的 秒数~~ 你要是计算时间间隔 可以 定义 2个变量 相减即可~
试着将该字符串转为date对象,里面好像有个方法。记不清了。
自己写了个
按照指定格式输入一个日期(可以增加个正则做判断)
我记得api里面有一个秒数可以化成日期的,但是有年月日
public class TimeToSecond {
public static void main(String[] args) {
String time ="01:22:12";
String[] my =time.split(":");
int hour =Integer.parseInt(my[0]);
int min =Integer.parseInt(my[1]);
int sec =Integer.parseInt(my[2]);
int zong =hour*3600+min*60+sec;
System.out.println("共"+zong+"秒");
}
}