0
public class CronoProgrammaForm {
    ...
    java.util.Date datPreIniLav;

    //getter and setter
    ...
}

Main

 SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");

 cronoProgrammaForm.setDatPreIniLav(df.parse(df.format(cronoProgrammaForm.getDatPreIniLav())));

cronoProgrammaForm.getDatPreIniLav() is 2015-10-14 df.format(cronoProgrammaForm.getDatPreIniLav()) is 14/10/2015

Why

sdf.parse(df.format(cronoProgrammaForm.getDatPreIniLav()))

is Wed Oct 14 00:00:00 CEST 2015?! I would it was 14/10/2015

Dave
  • 1,428
  • 4
  • 31
  • 49
  • 2
    because `SimpleDateFormat#parse` does parse the `String` into a `Date`. I´d guess what you are printing is what `Date#toString` does return, which should match your output. You might want to reformat it with `sdf.format(Date)`. But this isn´t a 100% correct hint, because your question does lack code to answer it correctly. – SomeJavaGuy May 06 '16 at 08:39
  • 3
    What is sdf? You only show the definition for df... – Joni May 06 '16 at 08:40
  • @KevinEsche, sorry I don't undestand..? – Dave May 06 '16 at 08:41
  • @Joni, it was my mistake :) – Dave May 06 '16 at 08:42
  • 1
    @DavideFruci how do you print the Date? do you do `...println(Date)` or `println(df.format(Date))`. I am quite sure that you are doing the first one, which does print the `String` representation of the `Date` by using the `Date#toString` method and not the formated `String` representation that you are trying to get. – SomeJavaGuy May 06 '16 at 08:43
  • @KevinEsche I don't printed the date yet, I saw the result of conversation during debugging. The method convert in json the CronoProgrammaForm object and, then, I print the json in the js – Dave May 06 '16 at 08:45
  • 2
    Your debugging output is just going to do a print on the Date as you are just storing a Date variable – Scary Wombat May 06 '16 at 08:47
  • @DavideFruci The `Date` object doesn´t save how it should be formated. If you want a `Date` object to be formated you allways have to format it like you did with `df.format`. The instance of `Date` doesn´t know which format it should use and will allways use the same format, which can be seen by you. In this case you shouldn´t mind because it will just show the output of `Date#toString` in the debugger. – SomeJavaGuy May 06 '16 at 08:47
  • @KevinEsche, So what should I do to resolve? – Dave May 06 '16 at 08:51

0 Answers0