public static void main(String[] args) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss");// HH:24小时制 String format2 = sdf.format(new Date()); System.out.println(format2);//18-03-19 23:01:07 SimpleDateFormat sdf2 = new SimpleDateFormat("yy-MM-dd"); String str = sdf.format(new Date());//String类型时间:18-03-19 23:01:07 System.out.println("String类型时间:"+str); Timestamp ts = new Timestamp(new Date().getTime()); System.out.println("TimeStamp:"+ts);//TimeStamp:2018-03-19 23:01:07.442 // 将当前时间前移两小时 求前移两小时后的时间 Long now = System.currentTimeMillis();//18-03-19 23:01:07 Long time2 = 1000*60*60*2L;//前移两小时 Long start = now -time2; Date date3 = new Date(); date3.setTime(start); String format = sdf.format(date3); System.out.println(format);//18-03-19 21:01:07 }