Java获取当前时间
import java.text.SimpleDateFormat;
import java.util.Date;
public class Datetest {
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 20:00:00");
public static void main(String[] args) {
//SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
//SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
Date date = new Date();
//String time = simpleDateFormat.format(date);
System.out.print(date);
System.out.print(time
}
}
SimpleDateFormat指定时间格式 2017-08-05 14:08:00,2017-08-05 20:00:00
System.out.print(date);直接输出当前时间,格式Sat Aug 05 14:05:31 CST 2017
Calendar currentDate = new GregorianCalendar();
currentDate.set(Calendar.HOUR_OF_DAY, 0);
currentDate.set(Calendar.MINUTE, 0);
currentDate.set(Calendar.SECOND, 0);
String startTime = simpleDateFormat.format(currentDate.getTime());
1.2017-08-05 00:00:00 第二种方式输出每天的开始时间。