package socket;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class aa {
public static void main(String[] args) throws ParseException{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date currentTime=new Date();
//将截取到的时间字符串转化为时间格式的字符串
Date beginTime=sdf.parse("1970-01-01 00:00:00");
//默认为毫秒
long interval=(currentTime.getTime()-beginTime.getTime());
System.out.println(interval);
}
}
本文介绍了一个简单的Java程序,该程序使用SimpleDateFormat类来解析特定格式的日期字符串,并计算从1970年1月1日至当前时间的时间间隔,单位为毫秒。
4634

被折叠的 条评论
为什么被折叠?



