获取日期前一天,字符串转时间戳
程序员文章站
2022-05-05 14:49:18
...
//获取日期前一天
public static void main(String[] args) throws ParseException {
SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd");
String a = "2019-12-01";
Date day= ss.parse(a);
long ms = day.getTime() - 1*24*3600*1000L;
Date prevDay = new Date(ms);
String pre = ss.format(prevDay);
System.out.println(pre);
}
日期转当天时间段
public static void main(String[] args) {
String time = "2019-12-01";
String begin = time.replaceAll("-", "") + "000000";
String end = time.replaceAll("-", "") + "235959";
System.out.println("begin:"+begin);
System.out.println("end:"+end);
}
//时间转时间戳
public static void main(String[] args) throws ParseException {
String a = "2019-12-03";
String b = a+" 00:00:00";
System.out.println(b);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long tt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(b).getTime()/1000;
System.out.println(tt);
}