androidandroid-studio-2.3

When i press a button how to get time at that time and set to a text field


Im trying to create a chat application (mobile app). When i press send button i need to set the time at the moment to a textview


Solution

  • You just have to get the current Date and time from system and then display on your textview. Try this -

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    your_textView.setText(dateFormat.format(new Date());