首页 > 编程知识 正文

java monthJava MonthDay getMonth用法及代码示例,python代码示例

时间:2023-05-05 13:25:02 阅读:246355 作者:3303

Java中MonthDay类的getMonth()方法从时间对象获取MonthDay的实例。

用法:

public Month getMonth()

参数:此方法不接受任何参数。

返回值:该函数返回month-of-year,并且不为null。

以下示例程序旨在说明MonthDay.getMonth()方法:

示例1:

// Program to illustrate the getMonth() method

import java.util.*;

import java.time.*;

public class GfG {

public static void main(String[] args)

{

// Parses the date

MonthDay tm1 = MonthDay.parse("--12-06");

// Uses the function

LocalDate dt1 = tm1.atYear(2018);

// Prints the date

System.out.println(dt1.getMonth());

}

}

输出:

DECEMBER

示例2:

// Program to illustrate the getMonth() method

import java.util.*;

import java.time.*;

public class GfG {

public static void main(String[] args)

{

// Parses the date

MonthDay tm1 = MonthDay.parse("--01-09");

// Uses the function

LocalDate dt1 = tm1.atYear(2016);

// Prints the date

System.out.println(dt1.getMonth());

}

}

输出:

JANUARY

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。