获取 android 当前时间的最后一个季度?
Get last quarter of current time in android?
我想在 android 获得当前时间的最后一个季度。
例如时间是12:45:00
,我需要:
12:30:00
12:45:00
或者时间是 10:50:00
我需要:
10:35:00
10:50:00
等等
我写了这段代码,结果为真:
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.setTime(cal.getTime());
cal.add(Calendar.MINUTE, -15);
String oneQuarterBack = dateFormat.format(cal.getTime());
但是如果我有 12:45:38
我该如何计算秒数?
Date date = new Date();
int lastQuarterInMillis = 900000;
date.setTime(System.currentTimeMillis() - lastQuarterInMillis);
SimpleDateFormat df = new SimpleDateFormat("hh:mm:ss");
String lastQuarter = df.format(date);
我想在 android 获得当前时间的最后一个季度。
例如时间是12:45:00
,我需要:
12:30:00
12:45:00
或者时间是 10:50:00
我需要:
10:35:00
10:50:00
等等
我写了这段代码,结果为真:
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.setTime(cal.getTime());
cal.add(Calendar.MINUTE, -15);
String oneQuarterBack = dateFormat.format(cal.getTime());
但是如果我有 12:45:38
我该如何计算秒数?
Date date = new Date();
int lastQuarterInMillis = 900000;
date.setTime(System.currentTimeMillis() - lastQuarterInMillis);
SimpleDateFormat df = new SimpleDateFormat("hh:mm:ss");
String lastQuarter = df.format(date);