java 时间处理

来源:互联网 发布:玛雅软件下载 编辑:程序博客网 时间:2024/06/10 15:04

1、获取当前时间戳

//方法 一  

System.currentTimeMillis();   

//方法 二  

Calendar.getInstance().getTimeInMillis();  

//方法 三  

new Date().getTime();  

2、时间和日期转换

把String类型的时间转换为Date类型  new SimpleDateFormat("yyyy-MM-dd").parse("1970-01-01").getTime()

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");java.util.Date time=null;try {   time= sdf.parse(sdf.format(new Date()));} catch (ParseException e) {   e.printStackTrace();}



0 0