java中常用到的获取格式化时间字符串
//根据传过来的date参数得到制定格式的时间字符串
public static String getCurrentDateTime3(Date date){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
//通过date对象得到n天后的格式化时间字符串
public static String getCurrentDateTime4(Date date,int day){//日期加上天数得到后来的日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long time=date.getTime();
day=day*24*60*60*1000;
time+=day;
Date newDate=new Date(time);
return sdf.format(newDate);
}
//通过date对象得到n天前的格式化时间字符串
public static String getCurrentDateTime5(Date date,int day){//日期减去天数得到后来的日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long time=date.getTime();
day=day*24*60*60*1000;
time-=day;
Date newDate=new Date(time);
return sdf.format(newDate);
}
相关文章
- Spring Boot中对接Twilio以实现发送验证码和验证短信码
- Spring Boot 3.5:这次更新让你连配置都不用写了,惊不惊喜?
- Spring Boot+Pinot实战:毫秒级实时竞价系统构建
- SpringBoot敏感配置项加密与解密实战
- SpringBoot 注解最全详解,建议收藏!
- Spring Boot 常用注解大全:从入门到进阶
- SpringBoot启动之谜:@SpringBootApplication如何让配置化繁为简
- Springboot集成Kafka原理_spring集成kafka的原理
- Spring Boot中@Data注解的深度解析与实战应用
- 大佬用1000字就把SpringBoot的配置文件讲的明明白白!