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));热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短