0

Looking for some help with LocalDate, I have so far come up with this:

public static String getDate(int days) {    
  LocalDate localDate = LocalDate.of(2017, 03, 04).plusDays(days);    
  return localDate.toString():
}

I need to return it as a string, but in this format: dd/mm/yyyy = 29/04/1991.

How can I achieve this?

DavidPostill
  • 7,734
  • 9
  • 41
  • 60
Speedychuck
  • 400
  • 9
  • 29
  • 2
    Use a [`DateTimeFormatter`](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html) to format your date as a string – Ferrybig Apr 25 '17 at 08:47
  • 1
    What did your research turn up? In what way was it insufficient? Tip: You may sometimes get faster answers from your search engine than from waiting for someone to type an answer here on Stack Overflow. – Ole V.V. Apr 25 '17 at 08:51
  • 1
    @Tom, it’s not an exact duplicate, but there’s certainly a wealth of good inspiration to be found in the question you are linking to. – Ole V.V. Apr 25 '17 at 09:07
  • @OleV.V. You may should re-read what "duplicate" means :). – Tom Apr 25 '17 at 09:13
  • Could be, @Tom. Where do you suggest I start reading? Asking after having done a superficial search myself and not finding much interesting. Mostly [Why are some questions marked as duplicate?](http://stackoverflow.com/help/duplicates). – Ole V.V. Apr 25 '17 at 09:26
  • 1
    Also a dup of [How to format LocalDate to string?](http://stackoverflow.com/q/28177370/642706) – Basil Bourque Apr 25 '17 at 14:24

1 Answers1

2

use DateTimeFormatter:

DateTimeFormatter formatter =
                  DateTimeFormatter.ofPattern("dd/MM/yyyy" );
return LocalDate.of(2017, 03, 04).plusDays(days).format(formatter);
Jens
  • 67,715
  • 15
  • 98
  • 113