Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
- private SimpleDateFormat sdfDiaSemana = new SimpleDateFormat("EEEE");
- private Calendar cal = Calendar.getInstance(new Locale("es","CL"));
- private TextView tvFecha;
- private Button btnOK;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- sdf.setLenient(false);
- tvFecha = findViewById(R.id.tvFecha);
- btnOK = findViewById(R.id.btnOK);
- btnOK.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Date fechaHoy = new Date();
- Date fecha, fechaNacimiento;
- cal.setTime(fechaHoy);
- for(int x = 1; x <= 24; ++x){
- cal.add(Calendar.DAY_OF_YEAR, 30);
- fecha = cal.getTime();
- Log.d("TAG_", sdf.format(fecha));
- }
- try{
- fechaNacimiento = sdf.parse("01/04/1997");
- Toast.makeText(MainActivity.this, sdfDiaSemana.format(fechaNacimiento), Toast.LENGTH_SHORT).show();
- }catch (Exception ex){
- Toast.makeText(MainActivity.this, "error fecha", Toast.LENGTH_SHORT).show();
- }
- cal.add(Calendar.YEAR, 10);
- fecha = cal.getTime();
- tvFecha.setText(sdf.format(fecha));
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement