获取系统当前时间:
<span style="font-family:SimSun;font-size:18px;"> private void setDate() {
//获取系统当前毫秒值
long currentTime = System.currentTimeMillis();
//构造方法内可以自定义显示格式
SimpleDateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
Date date = new Date(currentTime);
//指定格式的时间串
String time = dateFormat.format(date);
}</span>
<span style="font-family:SimSun;font-size:18px;"> try {
//先获取一个日历对象
Calendar calendar = Calendar.getInstance();
//将字符串按照指定的格式解析成Date类型的数据
Date date = new SimpleDateFormat("YYYYMMddHHmmss").parse("20160606060606");
//将Date类型数据放入日历对象
calendar.setTime(date);
//获取字符串对应时间
long millisTime = calendar.getTimeInMillis();
} catch (ParseException e) {
e.printStackTrace();
}</span>