1

I need to display timestamp in hh:mm format along with a toasted text. I have tried adding +DateUtils.HOUR_IN_MILLIS which isnt working for me

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

Edit: learnt from the answers that +Calendar.getInstance().getTime() does the job. Thanks. All the answers work great.

onexf
  • 3,244
  • 3
  • 20
  • 34

4 Answers4

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();
Rakesh
  • 761
  • 1
  • 9
  • 19
sasikumar
  • 10,919
  • 2
  • 21
  • 42
0

You can get current timestamp like this: https://stackoverflow.com/a/25264666/4310784

then u must just show it in your toast:

 Toast savedToast = Toast.makeText(getApplicationContext(),
            "Progress saved at"+String.valueOf(tsLong),Toast.LENGTH_SHORT);
    savedToast.show();
Community
  • 1
  • 1
Mohammad Zarei
  • 1,628
  • 12
  • 28
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();
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) {
        }
Febi M Felix
  • 2,611
  • 1
  • 8
  • 13