Created
October 9, 2024 13:56
-
-
Save diegoolipa/d238270c4cd2a0cb763a6be0d525b314 to your computer and use it in GitHub Desktop.
Date JAVA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Cliente { | |
private String nombre; | |
private Date fechaRegistro; | |
public String getNombre() { | |
return nombre; | |
} | |
public void setNombre(String nombre) { | |
this.nombre = nombre; | |
} | |
public Date getFechaRegistro() { | |
return fechaRegistro; | |
} | |
public void setFechaRegistro(String fechaRegistroStr) throws ParseException { | |
// Definir el formato de la fecha que esperas en el String | |
SimpleDateFormat formato = new SimpleDateFormat("yy-dd-MM"); | |
// Convertir el String a Date | |
this.fechaRegistro = formato.parse(fechaRegistroStr); | |
} | |
public void mostrarInfo() { | |
SimpleDateFormat formato = new SimpleDateFormat("yy-dd-MM"); | |
String fechaFormateada = formato.format(fechaRegistro); | |
System.out.println("Cliente: " + nombre); | |
System.out.println("Fecha de Registro: " + fechaFormateada); | |
} | |
} | |
//------------------------------------- | |
public static void main(String[] args) throws ParseException { | |
Cliente c = new Cliente(); | |
c.setNombre("Diego"); | |
c.setFechaRegistro("24-09-10"); | |
c.mostrarInfo(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment