【发布时间】:2023-12-27 21:44:01
【问题描述】:
我需要你的帮助 显示剩余分钟数而不是小时数
15 分钟而不是 15:30
示例: 开始预订的剩余时间:15 分钟
private Notification getNotification(Date countdownEnds) {
DateFormat timeFormat = countdownTimeFormatFactory.getTimeFormat();
String countdownEndsString = timeFormat.format(countdownEnds);
String title = resources.getString(R.string.countdown_notification_title);
String text = resources.getString(R.string.countdown_notification_text, countdownEndsString);
PendingIntent tapIntent =
PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(text)
.setTicker(title)
.setSmallIcon(R.mipmap.ic_launcher)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(tapIntent)
.setOngoing(true)
.setAutoCancel(false);
return builder.build();
}
public DateFormat getTimeFormat() {
return android.text.format.DateFormat.getTimeFormat(context);
}
kod:code
【问题讨论】:
-
15 分钟而不是 15:30。据我从您的问题 15 中了解到,这是没有意义的,是小时,而不是分钟
-
是不是让15:30是倒计时结束的时间(或者下午3:30)而时间是15:15,所以还有15分钟,你要显示“ 15分钟”?你可以从Java Calculate time until event from current time获得很多灵感。请搜索更多有趣和有用的问题和答案。
标签: android date time notifications sleep-mode