Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
  2.     private SimpleDateFormat sdfDiaSemana = new SimpleDateFormat("EEEE");
  3.     private Calendar cal = Calendar.getInstance(new Locale("es","CL"));
  4.  
  5.     private TextView tvFecha;
  6.     private Button btnOK;
  7.  
  8.  
  9.     @Override
  10.     protected void onCreate(Bundle savedInstanceState) {
  11.         super.onCreate(savedInstanceState);
  12.         setContentView(R.layout.activity_main);
  13.  
  14.         sdf.setLenient(false);
  15.  
  16.         tvFecha = findViewById(R.id.tvFecha);
  17.         btnOK = findViewById(R.id.btnOK);
  18.  
  19.         btnOK.setOnClickListener(new View.OnClickListener() {
  20.             @Override
  21.             public void onClick(View v) {
  22.                 Date fechaHoy = new Date();
  23.                 Date fecha, fechaNacimiento;
  24.  
  25.                 cal.setTime(fechaHoy);
  26.                 for(int x = 1; x <= 24; ++x){
  27.                     cal.add(Calendar.DAY_OF_YEAR, 30);
  28.                     fecha = cal.getTime();
  29.                     Log.d("TAG_", sdf.format(fecha));
  30.                 }
  31.  
  32.                 try{
  33.                     fechaNacimiento = sdf.parse("01/04/1997");
  34.                     Toast.makeText(MainActivity.this, sdfDiaSemana.format(fechaNacimiento), Toast.LENGTH_SHORT).show();
  35.                 }catch (Exception ex){
  36.                     Toast.makeText(MainActivity.this, "error fecha", Toast.LENGTH_SHORT).show();
  37.  
  38.                 }
  39.  
  40.                 cal.add(Calendar.YEAR, 10);
  41.                 fecha = cal.getTime();
  42.                 tvFecha.setText(sdf.format(fecha));
  43.             }
  44.         });
  45.  
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement