本文整理汇总了Java中java.time.LocalDateTime.get方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.get方法的具体用法?Java LocalDateTime.get怎么用?Java LocalDateTime.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setDateTimeAt
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void setDateTimeAt(byte[] buffer, int pos, LocalDateTime dateTime) {
int year, month, day, hour, min, sec;
year = dateTime.get(ChronoField.YEAR);
month = dateTime.get(ChronoField.MONTH_OF_YEAR);
day = dateTime.get(ChronoField.DAY_OF_MONTH);
hour = dateTime.get(ChronoField.HOUR_OF_DAY);
min = dateTime.get(ChronoField.MINUTE_OF_HOUR);
sec = dateTime.get(ChronoField.SECOND_OF_MINUTE);
// milli = dateTime.get(ChronoField.MILLI_OF_SECOND);
// // First two digits of miliseconds
// int msecH = milli / 10;
// // Last digit of miliseconds
// int msecL = milli % 10;
if (year > 1999) {
year -= 2000;
}
buffer[pos] = byteToBCD(year);
buffer[pos + 1] = byteToBCD(month);
buffer[pos + 2] = byteToBCD(day);
buffer[pos + 3] = byteToBCD(hour);
buffer[pos + 4] = byteToBCD(min);
buffer[pos + 5] = byteToBCD(sec);
buffer[pos + 6] = byteToBCD(0);
buffer[pos + 7] = byteToBCD(0);
}
示例2: getDateRelativeToToday
import java.time.LocalDateTime; //导入方法依赖的package包/类
private LocalDateTime getDateRelativeToToday(ChronoField field, int buffer) {
LocalDateTime date = LocalDateTime.now();
// want a date with a buffer either side of it and also not including the date itself
int gap = 2 * buffer + 1;
int max = (int)field.range().getSmallestMaximum();
int rand = getRandomInt(1, max - gap);
int value = rand >= date.get(field) - buffer ? rand + gap : rand;
LocalDateTime relativeDate = date.with(field, value);
// Adding logging to help with some spurious errors...
log.info("Date: " + date + " rand: " + rand + " value: " + value + " Picked date: " + relativeDate);
return relativeDate;
}