Autor
|
Tema: fecha con LocalDate (Leído 2,157 veces)
|
Beginner Web
Desconectado
Mensajes: 634
youtu.be/0YhflLRE-DA
|
Hola tengo una fecha creada con LocalDate y quiero cambiar su formato por este ejemplo “Viernes, 4 de Julio de 2004”.
|
|
|
En línea
|
7w7
|
|
|
|
rub'n
Desconectado
Mensajes: 1.217
(e -> λ("live now")); tatuar -> λ("α");
|
Chavalina que tal? Recuerdo que en un privado te mande algo parecido, no se si recuerdas, aquí te muestro pero en minúsculas, falta mostrar día y fecha en mayúsculas , no recuerdo, o procesar el String resultante, pero lo considero algo ineficienteprivate static final String PATTERN = "eeee, d 'de' MMMM 'de' uuuu";
return DateTimeFormater.ofPattern(PATTERN) .withZone(ZoneId.systemDefault()) . withLocale(new Locale("es", "AR")) .format(LocalDate.now()); }
Outputmartes, 23 de abril de 2019
|
|
« Última modificación: 23 Abril 2019, 16:05 pm por rub'n »
|
En línea
|
If you don't have time to read, you don't have the time (or the tools) to write, Simple as that. Stephen ki
|
|
|
Beginner Web
Desconectado
Mensajes: 634
youtu.be/0YhflLRE-DA
|
Bueno, se ve complicado, hasta ahora tengo hecho esto, no me gusta estar usando distintos tipos de clases para fechas Queria usar de tipo fecha LocalDate y el formateador unicamente, logré esto y ... ahora veo que hay un formateador para LocalDate package aplicacion.test; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.Date; import java.util.Scanner; /** * * @author Ana Kéldysh */ //Clase Principal que contiene el método main //Declaración del método main public static void main (String[] args ) { Scanner entrada = new Scanner (System. in); int dia, mes, año; System. out. println("Introduza fecha dd/MM/yyy: "); dia=entrada.nextInt(); mes=entrada.nextInt(); año=entrada.nextInt(); LocalDate fecha = LocalDate.of(año, mes, dia); LocalDate fecha2 = fecha.plusDays(100); } }
|
|
« Última modificación: 23 Abril 2019, 16:26 pm por Beginner Web »
|
En línea
|
7w7
|
|
|
rub'n
Desconectado
Mensajes: 1.217
(e -> λ("live now")); tatuar -> λ("α");
|
Vas bien, pero entonces de qué vale, ayudarte si dices que se ve complicado? Ya varias veces te he comentado que debes arriesgarte también XD, estoy desde el cell, luego lo formateo mejor.
Constantes private static final Map<Long, String> DIAS = new HashMap<>(); private static final Map<Long, String> MESES = new HashMap<>(); private static final Scanner LEER = new Scanner (System. in);
//Constructor public FormatearFecha() { fillMap(); fecha(); } private void fillMap() { DIAS.put(1L, "Lunes"); DIAS.put(2L, "Martes"); DIAS.put(3L, "Miércoles"); DIAS.put(4L, "Jueves"); DIAS.put(5L, "Viernes"); DIAS.put(6L, "Sábado"); DIAS.put(7L, "Domingo"); MESES.put(1L, "Enero"); MESES.put(2L, "Febrero"); MESES.put(3L, "Marzo"); MESES.put(4L, "Abril"); MESES.put(5L, "Mayo"); MESES.put(6L, "Junio"); MESES.put(7L, "Julio"); MESES.put(8L, "Agosto"); MESES.put(9L, "Septiembre"); MESES.put(10L, "Octubre"); MESES.put(11L, "Noviembre"); MESES.put(12L, "Diciembre"); } /** * dd/MM/yyyy * @return */ public void fecha() { System. out. println("Introduce fecha, tipo dd/MM/yyyy"); System. out. println("Introduce dia "); final int dia = LEER.nextInt(); System. out. println("Introduce Mes "); final int mes = LEER.nextInt(); System. out. println("Introduce Año "); final int año = LEER.nextInt(); LocalDate fecha = LocalDate.of(año, mes, dia); System. out. println(format (fecha )); } } } /** * Ejemplo de formato de salida, Miercoles, 24 de Abril de 2019 * @return */ public String format (final Temporal temporal ) { return new DateTimeFormatterBuilder() .appendText(ChronoField.DAY_OF_WEEK, DIAS ) .appendPattern(", d ") .appendLiteral("de ") .appendText(ChronoField.MONTH_OF_YEAR, MESES ) .appendLiteral(" de ") .appendPattern("uuuu ") . toFormatter(new Locale("es", "AR")) .withZone(ZoneId.systemDefault()) .format(temporal); }
|
|
« Última modificación: 4 Mayo 2019, 16:38 pm por rub'n »
|
En línea
|
If you don't have time to read, you don't have the time (or the tools) to write, Simple as that. Stephen ki
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
campos de fecha mysql y funciones de fecha php
PHP
|
SirLanceCC
|
9
|
9,348
|
3 Enero 2008, 12:36 pm
por Hans el Topo
|
|
|
Calcular dias entre Fecha A y Fecha B
« 1 2 »
.NET (C#, VB.NET, ASP)
|
Braayhaan
|
19
|
13,714
|
22 Julio 2010, 15:23 pm
por MANULOMM
|
|
|
cambiar la fecha del sistema tomando la fecha desde un archivo texto?
Scripting
|
.:UND3R:.
|
5
|
12,172
|
9 Septiembre 2011, 21:26 pm
por leogtz
|
|
|
como anular la fecha de un programita que tiene fecha de vencimiento
Ingeniería Inversa
|
quinipilar
|
3
|
5,095
|
19 Octubre 2011, 20:32 pm
por .:UND3R:.
|
|
|
Como insertar fecha en la que abrí por ultima vez un form(no la fecha actual) C#
.NET (C#, VB.NET, ASP)
|
arzteek
|
1
|
2,737
|
17 Julio 2013, 04:00 am
por Eleкtro
|
|