Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
¿Cómo analizar el objeto String to Date?

Estoy tratando de crear una variable de fecha basada en una fecha que he elegido. Cuando uso el formato de fecha simple para analizarlo en el objeto de fecha, no funcionará. ¿Me puede ayudar alguien, por favor?

 package com.example.rossr.tlatimetableweek; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import java.util.*; import java.text.*; public class A_Week extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_a__week); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); Date currentDate = new Date(); Log.i("Current Date",dateFormat.format(currentDate)); Date termDate = dateFormat.parse("11/12/2017"); //error on this line } }
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Prueba esto

 try { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); Date date = dateFormat.parse("11/12/2017") } catch (ParseException ex){ Log.i("Current Date","error occurred while parsing date"); }
over 4 years ago · Santiago Trujillo Report

0

Esto se debe a que el método DateFormat.parse lanza ParseException y debe manejarlo. declararlo en la firma del método o manejar la excepción con el bloque try and catch. he modificado el código para manejarlo con el bloque try and catch. intente con el siguiente código.

 DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); Date currentDate = new Date(); Log.i("Current Date",dateFormat.format(currentDate)); try { Date termDate = dateFormat.parse("11/12/2017"); System.out.println(" date ["+termDate+"]"); } catch (ParseException ex){ Log.i("Current Date","error occurred while parsing date"); }
over 4 years ago · Santiago Trujillo Report

0

Debe probar/atrapar la ParseException. Usar:

 try { Date termDate = dateFormat.parse("11/12/2017"); } catch (ParseException e) { e.printStackTrace(); }

El estudio de Android me sugirió esta solución. No estoy seguro, qué IDE está usando.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!