本文整理汇总了Java中java.time.LocalDateTime.getMonth方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.getMonth方法的具体用法?Java LocalDateTime.getMonth怎么用?Java LocalDateTime.getMonth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.getMonth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: localDateTime
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void localDateTime() {
LocalDateTime dateTime = LocalDateTime.of(2017, Month.SEPTEMBER, 20, 10, 6, 54);
DayOfWeek dayOfWeek = dateTime.getDayOfWeek();
Month month = dateTime.getMonth();
long year = dateTime.getLong(ChronoField.YEAR);
System.out.println(dateTime); //2017-09-20T10:06:54
System.out.println(dayOfWeek); //WEDNESDAY 星期三
System.out.println(month); //SEPTEMBER
System.out.println(year); //2017
Instant instant = dateTime.atZone(ZoneId.systemDefault()).toInstant();
Date date = Date.from(instant);
System.out.println(date); //Wed Sep 20 10:06:54 CST 2017
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd, yyyy - HH:mm");
LocalDateTime parse = LocalDateTime.parse("Nov 03, 2014 - 07:13", formatter);
System.out.println(parse); //2014-11-03T07:13
String string = parse.format(formatter);
System.out.println(string); //Nov 03, 2014 - 07:13
}
示例2: formatLocalName
import java.time.LocalDateTime; //导入方法依赖的package包/类
@SideOnly(Side.CLIENT)
public String formatLocalName(Component sub) {
LocalDateTime time = LocalDateTime.now();
if(time.getMonth() == Month.APRIL && time.getDayOfMonth() == 1) {
return "April Fools!";
}
String format = I18n.format(RandoresKeys.FORMAT);
String name = this.getName();
String compName = sub.getLocalName();
return format.replace("${name}", name).replace("${item}", compName);
}
示例3: isAprilFools
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static boolean isAprilFools() {
LocalDateTime now = LocalDateTime.now();
return now.getDayOfMonth()==1 && now.getMonth()==Month.APRIL;
}
示例4: testDateTimeInfo
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* 获取时间节点的详细信息
*/
@Test
public void testDateTimeInfo(){
LocalDateTime ldt = LocalDateTime.now();
// 获取当前的年份
int year = ldt.getYear();
System.out.println(year);
// 当前年中的第几天
int dayOfYear = ldt.getDayOfYear();
System.out.println(dayOfYear);
// 当前月份中的第几天
int dayOfMonth = ldt.getDayOfMonth();
System.out.println(dayOfMonth);
// 当前周中的第几天
DayOfWeek dayOfWeek = ldt.getDayOfWeek();
int dayOfWeekValue = dayOfWeek.getValue();
System.out.println(dayOfWeekValue);
// 获取小时
int hour = ldt.getHour();
System.out.println(hour);
// 获取月份信息
Month month = ldt.getMonth();
int monthValue = month.getValue();
System.out.println(monthValue);
int ldtMonthValue = ldt.getMonthValue();
System.out.println(ldtMonthValue);
// 获取分钟
int minute = ldt.getMinute();
System.out.println(minute);
}