-1
AttributeBinding attrs = 
    (AttributeBinding)bindingss.getControlBinding("FagDatfin");`

SimpleDateFormat fts = new SimpleDateFormat("dd/MM/yyyy");
String dateattrs = fts.format(attrs);
System.out.println(dateattrs);
Date date = fts.parse(dateattrs);`

attrs.setInputValue(date); 

how to decrement days -1 for example 23/04/2018 change to 22/04/2019

Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148
Souhaiel
  • 1
  • 5
  • prefer to use LocalDate rather than Date. Date is obsolete. LocalDate comes with its own, better-designed use classes and formatters. Then use plusDays(-1). – kumesana Apr 24 '19 at 13:58

1 Answers1

2

From Java 8, you can use DateTimeFormatter instead of SimpleDateFormat.

You will be able to convert the String to a LocalDate, which contains handy methods like... minusDays() :

DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDate localDate = LocalDate.from(dateTimeFormatter.parse("23/04/2018")).minusDays(1);
System.out.println(dateTimeFormatter.format(localDate));
Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148
  • if change LocalDate localDate = LocalDate.from(dateTimeFormatter.parse("23/04/2018")).minusDays(1); change LocalDate localDate = LocalDate.from(dateTimeFormatter.parse("attrs")).minusDays(1); Erreur – Souhaiel Apr 24 '19 at 14:32
  • @Souhaiel `dateTimeFormatter.parse("attrs")` does not make sense. You should parse a date. Somehing like `dateTimeFormatter.parse("25/12/2019")` – Arnaud Denoyelle Apr 24 '19 at 14:51
  • i like change this attribute value FagDatfin in AttributeBinding attrs = (AttributeBinding)bindingss.getControlBinding("FagDatfin");`AttributeBinding attrs = (AttributeBinding)bindingss.getControlBinding("FagDatfin"); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); LocalDate localDate = LocalDate.from(dateTimeFormatter.parse("attrs")).minusDays(1); System.out.println("test"+dateTimeFormatter.format(localDate)); – Souhaiel Apr 24 '19 at 15:18
  • @Souhaiel Can you try `dateTimeFormatter.parse(attrs.getInputValue())` ? – Arnaud Denoyelle Apr 24 '19 at 15:40
  • problem in type attribute FagDatfin TimesTamp but my value String – Souhaiel Apr 24 '19 at 16:14
  • @Souhaiel then [convert your Timestamp to a LocalDate](https://stackoverflow.com/questions/23263490/how-to-convert-java-sql-timestamp-to-localdate-java8-java-time) – Arnaud Denoyelle Apr 24 '19 at 16:17