Kamis, 01 November 2018

EditText DatePicker

DatePickerDialog picker;



txttgl_lahir= (EditText) findViewById(R.id.txttgl_lahir);
txttgl_lahir.setOnClickListener(new View.OnClickListener() {
   @Override   public void onClick(View v) {
      final Calendar cldr = Calendar.getInstance();
      int day = cldr.get(Calendar.DAY_OF_MONTH);
      int month = cldr.get(Calendar.MONTH)+1;
      int year = cldr.get(Calendar.YEAR);
      // date picker dialog      

picker = new DatePickerDialog(Profil.this,new DatePickerDialog.OnDateSetListener() {
@Override               
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                  String BUL="Januari";
                  int b=(monthOfYear + 1);
                  if(b==1){BUL="Januari";}
                  else if(b==2){BUL="Februari";}
                  else if(b==3){BUL="Maret";}
                  else if(b==4){BUL="Aprril";}
                  else if(b==5){BUL="Mei";}
                  else if(b==6){BUL="Juni";}
                  else if(b==7){BUL="Juli";}
                  else if(b==8){BUL="Agustus";}
                  else if(b==9){BUL="September";}
                  else if(b==10){BUL="Oktober";}
                  else if(b==11){BUL="November";}
                  else if(b==12){BUL="Desember";}

                  txttgl_lahir.setText(dayOfMonth + " " + BUL + " " + year);
               }
            }, year, month, day);
      picker.show();
   }
});





NB

Calendar cal = Calendar.getInstance();          
int jam = cal.get(Calendar.HOUR);
int menit= cal.get(Calendar.MINUTE);
int detik= cal.get(Calendar.SECOND);
int tgl= cal.get(Calendar.DATE);
int bln= cal.get(Calendar.MONTH)+1;
int thn= cal.get(Calendar.YEAR);
String BUL="Januari";
if(bln==1){BUL="Januari";}
                  else if(bln==2){BUL="Februari";}
                  else if(bln==3){BUL="Maret";}
                  else if(bln==4){BUL="Aprril";}
                  else if(bln==5){BUL="Mei";}
                  else if(bln==6){BUL="Juni";}
                  else if(bln==7){BUL="Juli";}
                  else if(bln==8){BUL="Agustus";}
                  else if(bln==9){BUL="September";}
                  else if(bln==10){BUL="Oktober";}
                  else if(bln==11){BUL="November";}
                  else if(bln==12){BUL="Desember";}

String swaktu=String.valueOf(tgl)+" "+BUL+" "+String.valueOf(thn);
String stgl=String.valueOf(tgl)+"-"+String.valueOf(bln)+"-"+String.valueOf(thn);
String sjam=String.valueOf(jam)+":"+String.valueOf(menit)+":"+String.valueOf(detik);




Tidak ada komentar:

Posting Komentar