Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    [JAVA]Problema con la data

    Ciao ragazzi!
    Ho un problemino. In un form l'utente deve inserire la data nel formato gg/mm/aaaa ma nel database la data si salva in formato aaaa-mm-gg.
    Se metto in una servlet

    ps.setDate(3,new java.sql.Date(new java.util.Date(data_in_input).getTime()));
    nel database il mese e il giorno si scambiano, ad esempio da 06/05/1984 ottengo 1984/06/05.
    C'è un modo semplice per risolvere il problema che non sia operare sulla stringa in input scambiando mese e giorno ?
    Grazie

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    Usa un DateFormat
    codice:
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Date myParsedDate = format.parse(Data_dal_database);
    L'oggetto date conterrà la data, che potrai riformattare come meglio credi
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  3. #3
    Grazie mille!
    anche se forse avevi capito male il problema (inserire una data dal formato gg/mm/aaaa ad aaaa-mm-gg e nn il contrario),usando sto codice ho risolto tutto !
    DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
    Date myParsedDate = format.parse(Data_dal_form);

    Thank you

  4. #4
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    Vabbhè dai il caffè deve ancora raggiungere il cervello...
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.