首页 > 编程语言 >Java生成当日日期 时间

Java生成当日日期 时间

时间:2023-01-30 19:36:41浏览次数:45  
标签:Java String SimpleDateFormat 日期 new calendar 生成 Calendar


Java生成当日日期 时间

生成当前日期时间

//当前日期时间方法 string类型
public static String newDateTime(){
SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String datetime = tempDate.format(new java.util.Date());
return datetime;
}

生成昨日日期

//生成昨日的日期
public static String newYesterdayDate(){
DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar=Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,-24);
String yesterdayDate=dateFormat.format(calendar.getTime());
return yesterdayDate;
}


标签:Java,String,SimpleDateFormat,日期,new,calendar,生成,Calendar
From: https://blog.51cto.com/u_15948415/6027750

相关文章