赞
踩
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); // 格式化
Date date = new Date();
System.out.println(sdf.format(date)); // 2023-10-23 08:36:20
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); // 格式化
Calendar calendar = Calendar.getInstance();
System.out.println(sdf.format(calendar.getTime())); // 2023-10-23 08:36:20
int year = calendar.get(Calendar.YEAR); //获取当前年份
int mon = calendar.get(Calendar.MONTH); //获取当前月份 0-11月
if (mon < 12) {
mon += 1;
}
int day = calendar.get(Calendar.DATE); //获取当前日
int hour = calendar.get(Calendar.HOUR_OF_DAY); //获取当前时
int minute = calendar.get(Calendar.MINUTE); //获取当前分
int second = calendar.get(Calendar.SECOND); //获取当前秒
System.out.println(year + "-" + mon + "-" + day + " " + hour + ":" + minute + ":" + second); // 2023-10-23 20:36:20
//获取当前日期
LocalDate localDate = LocalDate.now();
System.out.println(localDate); // 2023-10-23
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。