Get current date and time in textView android

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

how to get current date and time in textView android

i am using following code

Calendar c1 = Calendar.getInstance();
    SimpleDateFormat sdf1 = new SimpleDateFormat("d / MMM / yyyy");
    String strdate1 = sdf1.format(c1.getTime());

    TextView txtdate1 = (TextView) findViewById(R.id.current_date_view);
    txtdate1.setText(strdate1);

    Calendar c2 = Calendar.getInstance();
    SimpleDateFormat sdf2 = new SimpleDateFormat("h : MM : a");
    String strdate2 = sdf2.format(c2.getTime());

    TextView txtdate2 = (TextView) findViewById(R.id.current_time_view);
    txtdate2.setText(strdate2);

but this is not working below API 23

Answers

use like this

SimpleDateFormat sdf1 = new SimpleDateFormat("d / MMM / yyyy",Locale.ENGLISH);

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/37928273/get-current-date-and-time-in-textview-android

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils