在toast中显示时间戳

时间:2016-03-02 11:33:22

标签: android timestamp android-toast

我需要以hh:mm格式显示时间戳以及烘烤文本。我尝试添加 Toast savedToast = Toast.makeText(getApplicationContext(), "Progress saved at"+DateUtils.HOUR_IN_MILLIS,Toast.LENGTH_SHORT); savedToast.show(); 这对我不起作用

+Calendar.getInstance().getTime()

编辑:从.concat()完成工作的答案中学习。谢谢。所有答案都很有效。

4 个答案:

答案 0 :(得分:1)

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();

答案 1 :(得分:0)

你可以得到这样的当前时间戳: https://stackoverflow.com/a/25264666/4310784

然后你必须在吐司中展示它:

 Toast savedToast = Toast.makeText(getApplicationContext(),
            "Progress saved at"+String.valueOf(tsLong),Toast.LENGTH_SHORT);
    savedToast.show();

答案 2 :(得分:0)

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();

答案 3 :(得分:0)

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) {
        }