Java中的MonthDay format()方法
可以使用format()Java中MonthDay类中的方法,使用指定的格式化程序对MonthDay进行格式化。此方法需要单个参数,即要格式化的MonthDay对象,并且它使用指定的格式化程序返回格式化的MonthDay。
演示此程序如下
示例
import java.time.*;
import java.time.temporal.*;
import java.time.format.DateTimeFormatter;
public class Demo {
public static void main(String[] args) {
MonthDay md = MonthDay.parse("--02-22");
LocalDate ld = md.atYear(2019);
System.out.println("The MonthDay is: " + md);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("YYYY-MM-dd");
System.out.println("The formatted MonthDay is: " + dtf.format(ld));
}
}输出结果
The MonthDay is: --02-22 The formatted MonthDay is: 2019-02-22
现在让我们了解上面的程序。
首先显示MonthDay。然后,使用指定的格式化程序使用该format()方法对MonthDay进行格式化,并显示已格式化的MonthDay。演示此代码段如下所示:
MonthDay md = MonthDay.parse("--02-22");
LocalDate ld = md.atYear(2019);
System.out.println("The MonthDay is: " + md);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("YYYY-MM-dd");
System.out.println("The formatted MonthDay is: " + dtf.format(ld));热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短