本文整理汇总了Java中java.time.LocalDateTime.getDayOfWeek方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.getDayOfWeek方法的具体用法?Java LocalDateTime.getDayOfWeek怎么用?Java LocalDateTime.getDayOfWeek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.getDayOfWeek方法的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: checkHarvestedCrops
import java.time.LocalDateTime; //导入方法依赖的package包/类
@SubscribeEvent
public void checkHarvestedCrops(BlockEvent.HarvestDropsEvent event) {
Block crop = event.getState().getBlock();
if (event.getHarvester() != null && event.getHarvester().capabilities.isCreativeMode)
return;
if (crop == UCBlocks.cropInvisibilia) {
if (event.getHarvester() == null)
{
event.getDrops().clear();
event.setResult(Result.DEFAULT);
}
}
if (crop == UCBlocks.cropFeroxia && ((Feroxia)crop).isFullyGrown(event.getWorld(), event.getPos(), event.getState())) {
if (event.getHarvester() != null && !(event.getHarvester() instanceof FakePlayer))
GrowthSteps.generateSteps(event.getHarvester());
else
event.getDrops().clear();
event.setResult(Result.DEFAULT);
}
if (crop == UCBlocks.cropDyeius && !event.getDrops().isEmpty()) {
for (ItemStack stack : event.getDrops()) {
if (stack.getItem() == Items.DYE)
{
long time = event.getWorld().getWorldTime() % 24000L;
int meta = (int)(time / 1500);
LocalDateTime current = LocalDateTime.now();
if (current.getDayOfWeek() == DayOfWeek.FRIDAY)
stack.setItemDamage(EnumDyeColor.byMetadata(meta).getMetadata());
else
stack.setItemDamage(EnumDyeColor.byMetadata(meta).getDyeDamage());
}
}
}
}
示例3: isNeededToLaunch
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Vérifie si le batch doit être lancé grace a son schedul
*
* @param batch
* @param lastExec
* @return true si le batch doit etre lance ou non
*/
private Boolean isNeededToLaunch(Batch batch, LocalDateTime lastExec) {
/* Vérification si le batch doit etre lancé immediatement */
if (batch.getTemIsLaunchImediaBatch()) {
batch.setTemIsLaunchImediaBatch(false);
batchRepository.saveAndFlush(batch);
return true;
}
LocalDateTime now = LocalDateTime.now();
/* Vérification si le batch doit etre lancé à une date précise */
if (batch.getFixeYearBatch() != null && batch.getFixeMonthBatch() != null && batch.getFixeDayBatch() != null) {
if (now.getYear() != batch.getFixeYearBatch() || now.getMonth().getValue() != batch.getFixeMonthBatch()
|| now.getDayOfMonth() != batch.getFixeDayBatch()) {
return false;
}
}
/*
* Vérification si le batch doit etre lancé annuelement avec un mois donné et un
* jour donné
*/
if (batch.getFixeMonthBatch() != null && batch.getFixeDayBatch() != null) {
if (now.getMonth().getValue() != batch.getFixeMonthBatch()
|| now.getDayOfMonth() != batch.getFixeDayBatch()) {
return false;
}
}
/* Vérification si le batch doit etre lancé mensuelement avec un jour donné */
else if (batch.getFixeDayBatch() != null) {
if (now.getDayOfMonth() != batch.getFixeDayBatch()) {
return false;
}
}
/*
* Sinon vérification si le batch doit etre lancé hebdo avec les journs précisés
*/
else {
DayOfWeek today = now.getDayOfWeek();
if (!batch.getTemLundiBatch() && today.getValue() == 1) {
return false;
} else if (!batch.getTemMardiBatch() && today.getValue() == 2) {
return false;
} else if (!batch.getTemMercrBatch() && today.getValue() == 3) {
return false;
} else if (!batch.getTemJeudiBatch() && today.getValue() == 4) {
return false;
} else if (!batch.getTemVendrediBatch() && today.getValue() == 5) {
return false;
} else if (!batch.getTemSamediBatch() && today.getValue() == 6) {
return false;
} else if (!batch.getTemDimanBatch() && today.getValue() == 7) {
return false;
}
}
logger.trace("OK à lancer aujourd'hui");
if ((batch.getFixeHourBatch().isAfter(lastExec.toLocalTime()))
&& batch.getFixeHourBatch().isBefore(now.toLocalTime())) {
logger.trace("OK à lancer maintenant");
return true;
}
return false;
}
示例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);
}