如何将LocalDate格式化为字符串? [英] How to format LocalDate to string?

查看:573
本文介绍了如何将LocalDate格式化为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为date的LocalDate变量,当我打印它显示1988-05-05我需要转换它打印为05.May 1988.How怎么做?

I have a LocalDate variable called date,when I print it displays 1988-05-05 I need to convert this to be printed as 05.May 1988.How to do this?

推荐答案

如果他使用Java 8中新增的LocalDate,SimpleDateFormat将无法工作。从我所看到的,你将不得不使用DateTimeFormatter, http://docs.oracle.com/javase/8/docs/ api / java / time / format / DateTimeFormatter.html

SimpleDateFormat will not work if he is starting with LocalDate which is new in Java 8. From what I can see, you will have to use DateTimeFormatter, http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html.

LocalDate localDate = LocalDate.now();//For reference
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy");
String formattedString = localDate.format(formatter);

应该打印在1988年5月5日。要获得一天之后和月之前的期限,你可能会必须使用dd'.LLLL y​​yyy

That should print 05 May 1988. To get the period after the day and before the month, you might have to use "dd'.LLLL yyyy"

这篇关于如何将LocalDate格式化为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆