2017-04-25 61 views
0

尋找一些幫助LOCALDATE的,到目前爲止我想出了這個:的Java格式LOCALDATE

public static String getDate(int days){ 

LocalDate localDate = LocalDate.of(2017, 03, 04).plusDays(days); 

return localDate.toString(): 
} 

我需要把它作爲字符串返回,但這種格式DD/MM/YYYY = 29/04/1991。

我該如何做到這一點?

謝謝。

+2

使用['DateTimeFormatter'](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html)至將日期格式化爲字符串 – Ferrybig

+1

您的研究成果是什麼?它以什麼方式不足?提示:您有時可能會從搜索引擎中獲得更快的答案,而不是等待某人在Stack Overflow中輸入答案。 –

+1

@Tom,它不是一個完全相同的副本,但在鏈接到的問題中肯定有很多好的靈感。 –

回答

2

DateTimeFormatter使用:

DateTimeFormatter formatter = 
        DateTimeFormatter.ofPattern("dd/MM/yyyy"); 
return LocalDate.of(2017, 03, 04).plusDays(days).format(formatter);