Display default date in EditText widgets

How can I dynamically display the current date in the text of an EditText widget at run time?

Thanks patrick

+3
source share
2 answers

If your EditText file is declared in an xml file, you should get it in code like this

EditText editText = (EditText) findViewById( R.id.your_edittext_id );

Then you can easily update it with the current date.

SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" ); 
editText.setText( sdf.format( new Date() ));
+10
source

... it is even better to use the locale and user formatting options:

editText.setText( DateFormat.getDateInstance().format(new Date()) );
+1
source

Source: https://habr.com/ru/post/1727403/


All Articles