在吐司中显示时间戳

displaying timestamp in toast

我需要以 hh:mm 格式显示时间戳以及烘烤文本。我试过添加 +DateUtils.HOUR_IN_MILLIS 但对我不起作用

 Toast savedToast = Toast.makeText(getApplicationContext(),
                "Progress saved at"+DateUtils.HOUR_IN_MILLIS,Toast.LENGTH_SHORT);
        savedToast.show();

编辑:从 +Calendar.getInstance().getTime() 的答案中了解到。谢谢。所有答案都很好。

Calendar now = Calendar.getInstance();
final int hour = now.get(Calendar.HOUR_OF_DAY);
final int minute = now.get(Calendar.MINUTE);
Toast savedToast = Toast.makeText(getApplicationContext(),
            "Progress saved at"+String.valueOf(hour )+":"+String.valueOf(minute ),Toast.LENGTH_SHORT);
    savedToast.show();

您可以像这样获取当前时间戳:

那么你必须在你的 toast 中展示它:

 Toast savedToast = Toast.makeText(getApplicationContext(),
            "Progress saved at"+String.valueOf(tsLong),Toast.LENGTH_SHORT);
    savedToast.show();
SimpleDateFormat df = new SimpleDateFormat("hh:mm");     
Calendar c = Calendar.getInstance();
String str_time = df.format(c.getTime());
Toast.makeText(getApplicationContext(), "Progress saved at"+str_time,Toast.LENGTH_SHORT).show();
try {
            DateFormat sdf  = new SimpleDateFormat("hh:mm a");
            Date netDate    = (new Date());
            String dateString      = sdf.format(netDate);
            Toast savedToast = Toast.makeText(getApplicationContext(),
                    "Progress saved at " + dateString, Toast.LENGTH_SHORT);
            savedToast.show();
        } catch(Exception ex) {
        }