1.获得N天前的TIMESTAMP
1 Calendar cl = Calendar.getInstance(); 2 cl.add(Calendar.DAY_OF_YEAR, -7); 3 Date date = cl.getTime(); 4 long time = date.getTime(); 5 Timestamp timestamp = new Timestamp(time);
2.程序启动当前时间和任务执行既定时间
1 /* 2 delegate time 3 */ 4 String time="20:00"; 5 6 /* 7 simpledateformat can parse String to Date, format Date to String 8 */ 9 DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm"); 10 DateFormat dayFormat = new SimpleDateFormat("yy-MM-dd"); 11 12 Date curDate = dateFormat.parse(dayFormat.format(new Date()) + " " + time); 13 14 Long current =System.currentTimeMillis(); 15 Long certain = curDate.getTime();
时间: 2024-10-11 00:25:21