看好了,我只表演一次
public class Day30Test {
public static void main(String[] args) throws ParseException {
// int cacheTime = getTodayRemainSeconds().intValue();
// System.out.println(cacheTime+"秒");
// String s = secondConvertHourMinSecond(Long.valueOf(cacheTime));
// System.out.println(s);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH,-31);
Date time = calendar.getTime();
//Sun Oct 30 15:35:57 CST 2022
System.out.println(calendar.getTime());
String dateStr = "Sun Oct 30 15:35:57 CST 2022";
DateFormat cst = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateFormat gmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
Date dateTime = gmt.parse(dateStr);
String dateString = cst.format(dateTime);
System.out.println(dateString);
}
public static final long MILLIS_OF_DAY = 86400000;
public static Long getTodayRemainSeconds() {
Calendar ca = Calendar.getInstance();
ca.set(Calendar.HOUR_OF_DAY, 0);
ca.set(Calendar.MINUTE, 0);
ca.set(Calendar.SECOND, 0);
ca.setTimeInMillis(((ca.getTimeInMillis() + MILLIS_OF_DAY)/ 1000L) * 1000L);
Date date = ca.getTime();
return (date.getTime() - System.currentTimeMillis())/1000;
}
public static String secondConvertHourMinSecond(Long second) {
String str = "00:00:00";
if (second == null || second < 0) {
return str;
}
// 得到小时
long h = second / 3600;
str = h > 0 ? ((h < 10 ? ("0" + h) : h) + ":") : "00:";
// 得到分钟
long m = (second % 3600) / 60;
str += (m < 10 ? ("0" + m) : m) + ":";
//得到剩余秒
long s = second % 60;
str += (s < 10 ? ("0" + s) : s);
return str;
}
}