本文整理匯總了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);
}