本文整理汇总了Java中java.time.LocalDateTime.getHour方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.getHour方法的具体用法?Java LocalDateTime.getHour怎么用?Java LocalDateTime.getHour使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.getHour方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeDateTimeUntil
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void writeDateTimeUntil(LocalDateTime dateTime, ByteArrayOutputStream bos) {
// this is frigging confusing.. who the hell did think about this...
// the first three bits are the months
// next five bits are the day
// next bit is always 0
// next bit is the month again (the very first one)
// next bit is always 0
// last five bits are the year
// only the first three bits!
// int month = (positiveFirst >> 5 << 1) + (64 >> 6 & 1);
int month = dateTime.getMonthValue();
int monthAndDay = (month << 4 & 224) + dateTime.getDayOfMonth();
bos.write(monthAndDay);
int monthAndYear = (month % 2 == 1 ? 128 : 0) + (dateTime.getYear() - 2000);
bos.write(monthAndYear);
int halfhours = (dateTime.getHour() * 2) + (dateTime.getMinute() == 30 ? 1 : 0);
bos.write(halfhours);
}
示例2: javaToDosTime
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Converts Java time to DOS time.
*/
private static long javaToDosTime(long time) {
Instant instant = Instant.ofEpochMilli(time);
LocalDateTime ldt = LocalDateTime.ofInstant(
instant, ZoneId.systemDefault());
int year = ldt.getYear() - 1980;
if (year < 0) {
return (1 << 21) | (1 << 16);
}
return (year << 25 |
ldt.getMonthValue() << 21 |
ldt.getDayOfMonth() << 16 |
ldt.getHour() << 11 |
ldt.getMinute() << 5 |
ldt.getSecond() >> 1) & 0xffffffffL;
}
示例3: testRangeOfLocalDateTimes
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider = "LocalDateTimeRanges")
public void testRangeOfLocalDateTimes(LocalDateTime start, LocalDateTime end, Duration step, boolean parallel) {
final boolean ascend = start.isBefore(end);
final Range<LocalDateTime> range = Range.of(start, end, step, v -> v.getHour() == 6);
final Array<LocalDateTime> array = range.toArray(parallel);
final LocalDateTime first = array.first(v -> true).map(ArrayValue::getValue).get();
final LocalDateTime last = array.last(v -> true).map(ArrayValue::getValue).get();
Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATETIME);
Assert.assertTrue(!array.style().isSparse());
Assert.assertEquals(range.start(), start, "The range start");
Assert.assertEquals(range.end(), end, "The range end");
int index = 0;
LocalDateTime value = first;
while (ascend ? value.isBefore(last) : value.isAfter(last)) {
final LocalDateTime actual = array.getValue(index);
Assert.assertEquals(actual, value, "Value matches at " + index);
Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
value = ascend ? value.plus(step) : value.minus(step);
while (value.getHour() == 6) value = ascend ? value.plus(step) : value.minus(step);
index++;
}
}
示例4: convertToPresentation
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Override
public String convertToPresentation(LocalDateTime value, Class<? extends String> targetType, Locale locale)
throws ConversionException {
if (value==null){
return null;
}
if (value.getHour()==0 && value.getMinute()==0 && value.getSecond()==0){
return formatterDate.format(value);
}
return formatterDateTime.format(value);
}
示例5: dateFormatterForLogs
import java.time.LocalDateTime; //导入方法依赖的package包/类
private static String dateFormatterForLogs(LocalDateTime dateTime) {
String dateString = "[";
dateString += dateTime.getDayOfMonth() + "_";
dateString += dateTime.getMonthValue() + "_";
dateString += dateTime.getYear() + "_";
dateString += dateTime.getHour() + ":";
dateString += dateTime.getMinute() + ":";
dateString += dateTime.getSecond();
dateString += "] ";
return dateString;
}
示例6: adjust_sinyee_time
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static int adjust_sinyee_time(final int time) {
LocalDateTime ldt = DateTimeHelper.Long2Ldt(time);
int hour = ldt.getHour();
if (hour < 8) {
if (ldt.getDayOfWeek().equals(DayOfWeek.MONDAY)) {
return time - 52 * 3600;
} else {
return time - 4 * 3600;
}
} else {
return time;
}
}
示例7: javaToDosTime
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static long javaToDosTime(long time) {
Instant instant = Instant.ofEpochMilli(time);
LocalDateTime ldt = LocalDateTime.ofInstant(
instant, ZoneId.systemDefault());
int year = ldt.getYear() - 1980;
if (year < 0) {
return (1 << 21) | (1 << 16);
}
return (year << 25 |
ldt.getMonthValue() << 21 |
ldt.getDayOfMonth() << 16 |
ldt.getHour() << 11 |
ldt.getMinute() << 5 |
ldt.getSecond() >> 1) & 0xffffffffL;
}
示例8: DateTimeParameterObject
import java.time.LocalDateTime; //导入方法依赖的package包/类
DateTimeParameterObject(final LocalDateTime localDateTime, @Nullable final String pattern) {
this.localDateTime = localDateTime;
this.pattern = Optional.ofNullable(pattern);
this.dayOfMonth = localDateTime.getDayOfMonth();
this.month = localDateTime.getMonthValue();
this.year = localDateTime.getYear();
this.hour = localDateTime.getHour();
this.minute = localDateTime.getMinute();
this.second = localDateTime.getSecond();
this.instant = localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond();
}
示例9: isTooLateForToday
import java.time.LocalDateTime; //导入方法依赖的package包/类
private boolean isTooLateForToday(LocalDateTime dateTime) {
return dateTime.getHour() >= endOfBusinessDayHour;
}
示例10: 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);
}
示例11: valueOf
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
* object, with the same year, month, day of month, hours, minutes,
* seconds and nanos date-time value as the provided {@code LocalDateTime}.
* <p>
* The provided {@code LocalDateTime} is interpreted as the local
* date-time in the local time zone.
*
* @param dateTime a {@code LocalDateTime} to convert
* @return a {@code Timestamp} object
* @exception NullPointerException if {@code dateTime} is null.
* @since 1.8
*/
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
return new Timestamp(dateTime.getYear() - 1900,
dateTime.getMonthValue() - 1,
dateTime.getDayOfMonth(),
dateTime.getHour(),
dateTime.getMinute(),
dateTime.getSecond(),
dateTime.getNano());
}