本文整理了Java中java.time.LocalDateTime.getDayOfYear()
方法的一些代码示例,展示了LocalDateTime.getDayOfYear()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.getDayOfYear()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:getDayOfYear
[英]Gets the day-of-year field.
This method returns the primitive int value for the day-of-year.
[中]获取“年度日期”字段。
此方法返回一年中某一天的原始int值。
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testYearDay() {
LocalDateTime dateTime = LocalDateTime.of(2018, 4, 10, 7, 30);
startCol.append(dateTime);
StringColumn yearDay = startCol.yearDay();
assertEquals(
"2018-" +
Strings.padStart(String.valueOf(dateTime.getDayOfYear()), 3, '0'),
yearDay.get(0));
}
代码示例来源:origin: SeanDragon/protools
/**
* 获取天在这年的次序
*
* @return 天
*/
public int getDayOfYear() {
return this.localDateTime.getDayOfYear();
}
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testAsLocalDateTime() {
LocalDateTime dateTime = LocalDateTime.now();
long packed = pack(dateTime.toLocalDate(), dateTime.toLocalTime());
LocalDateTime upacked = asLocalDateTime(packed);
assertEquals(dateTime.getDayOfYear(), upacked.getDayOfYear());
assertEquals(dateTime.getHour(), upacked.getHour());
assertEquals(dateTime.getMinute(), upacked.getMinute());
assertEquals(dateTime.getSecond(), upacked.getSecond());
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Gets the day-of-year field.
* <p>
* This method returns the primitive {@code int} value for the day-of-year.
*
* @return the day-of-year, from 1 to 365, or 366 in a leap year
*/
public int getDayOfYear() {
return dateTime.getDayOfYear();
}
代码示例来源:origin: com.liumapp.qtools.date/qtools-date
/**
* 获取天在这年的次序
*
* @return 天
*/
public int getDayOfYear() {
return this.localDateTime.getDayOfYear();
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Gets the day-of-year field.
* <p>
* This method returns the primitive {@code int} value for the day-of-year.
*
* @return the day-of-year, from 1 to 365, or 366 in a leap year
*/
public int getDayOfYear() {
return dateTime.getDayOfYear();
}
代码示例来源:origin: espertechinc/esper
public Object evaluateInternal(LocalDateTime ldt) {
return ldt.getDayOfYear();
}
代码示例来源:origin: jzyong/game-server
/**
* 获取传入毫秒的天 1 to 365, or 366
*
* @param time
* @return
*/
public static int getDayOfYear(long time) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()).getDayOfYear();
}
代码示例来源:origin: stackoverflow.com
long millis1 = System.currentTimeMillis();
...
long millis2 = System.currentTimeMillis();
Instant instant1 = Instant.EPOCH.plusMillis(millis1);
Instant instant2 = Instant.EPOCH.plusMillis(millis2);
LocalDateTime t1 = LocalDateTime.ofInstant(instant1, ZoneId.systemDefault());
LocalDateTime t2 = LocalDateTime.ofInstant(instant2, ZoneId.systemDefault());
System.out.println("same day: " + (t1.getDayOfYear() == t2.getDayOfYear()));
System.out.println("t1+3h >= t2: " + (t1.plusHours(3).compareTo(t2) >= 0));
代码示例来源:origin: jzyong/game-server
/**
* 获取系统当前的天 1 to 365, or 366
*
* @return
*/
public static int getDayOfYear() {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault()).getDayOfYear();
}
代码示例来源:origin: jzyong/game-server
/**
* 返回当年第一天格式
*
* @param formatter
* @return
*/
public static String getNowYearFirstDayFormat(DateTimeFormatter formatter) {
LocalDateTime ldt = LocalDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault());
ldt = LocalDateTime.of(ldt.minusDays(ldt.getDayOfYear() - 1).toLocalDate(), LocalTime.MIN);
return ldt.format(formatter);
}
代码示例来源:origin: com.healthmarketscience.jackcess/jackcess
private static int getDayDiff(LocalDateTime ldt1, LocalDateTime ldt2) {
int y1 = ldt1.getYear();
int d1 = ldt1.getDayOfYear();
int y2 = ldt2.getYear();
int d2 = ldt2.getDayOfYear();
while(y2 > y1) {
ldt2 = ldt2.minusYears(1);
d2 += ldt2.range(ChronoField.DAY_OF_YEAR).getMaximum();
y2 = ldt2.getYear();
}
return d2 - d1;
}
代码示例来源:origin: ysc/data-generator
private static List<Map<String, Object>> getDayData(int startYear, int startMonth, int startDay){
List<Map<String, Object>> data = new ArrayList<>();
LocalDateTime start = LocalDateTime.of(startYear, startMonth, startDay, 0, 0, 0, 0);
LocalDateTime end = LocalDateTime.now();
while(start.isBefore(end)) {
String date = TimeUtils.toString(start, "yyyy-MM-dd");
int dayofweek = start.getDayOfWeek().getValue();
int dayofyear = start.getDayOfYear();
int weekofyear = ((dayofyear-1) / 7)+1;
int month = start.getMonth().getValue();
int dayofmonth = start.getDayOfMonth();
int quarter = ((month-1) / 3) + 1;
int year = start.getYear();
Map<String, Object> map = new HashMap<>();
map.put("day_str", date+" 00:00:00");
map.put("dayofweek", dayofweek);
map.put("dayofyear", dayofyear);
map.put("weekofyear", weekofyear);
map.put("month", month);
map.put("dayofmonth", dayofmonth);
map.put("quarter", quarter);
map.put("year", year);
data.add(map);
start = start.plusDays(1);
}
return data;
}
代码示例来源:origin: com.querydsl/querydsl-sql
@Test
public void get() throws SQLException {
ResultSet resultSet = EasyMock.createNiceMock(ResultSet.class);
EasyMock.expect(resultSet.getTimestamp(1, UTC)).andReturn(new Timestamp(UTC.getTimeInMillis()));
EasyMock.replay(resultSet);
LocalDateTime result = type.getValue(resultSet, 1);
EasyMock.verify(resultSet);
assertNotNull(result);
assertTrue(result.getDayOfYear() == 1);
}
}
代码示例来源:origin: stackoverflow.com
LocalDateTime now = LocalDateTime.now();
int year = now.getYear();
int month = now.getMonthValue();
int day = now.getDayOfMonth();
int hour = now.getHour();
int minute = now.getMinute();
// your answer
int dayOfYear = now.getDayOfYear();
代码示例来源:origin: olehmberg/winter
@Override
public double calculate(LocalDateTime first, LocalDateTime second) {
if(first==null || second==null) {
return 0.0;
}
if(first.getDayOfYear() == 1 || second.getDayOfYear() == 1) {
double yearSim = 1.0 - ((double)Math.abs(first.getYear() - second.getYear()) / (double)Math.abs(yearRange));
return Math.max(yearSim, 0.0);
}
int days = Math.abs(first.getDayOfMonth() - second.getDayOfMonth());
int months = Math.abs(first.getMonthValue() - second.getMonthValue());
double daySim = (31.0 - days) / 31.0;
double monthSim = (12.0 - months) / 12.0;
double yearSim = 1.0 - ((double)Math.abs(first.getYear() - second.getYear()) / (double)Math.abs(yearRange));
if(yearSim<0.0) {
// outside of year range
return 0.0;
} else {
daySim = getDayWeight()*daySim;
monthSim = getMonthWeight()*monthSim;
yearSim = getYearWeight()*yearSim;
double value = daySim + monthSim + yearSim;
value = value/(getDayWeight()+getMonthWeight()+getYearWeight());
return value;
}
}
代码示例来源:origin: com.healthmarketscience.jackcess/jackcess
result = param2.getAsLocalDateTime(ctx).getMonthValue();
} else if(intv.equalsIgnoreCase(INTV_DAY_OF_YEAR)) {
result = param2.getAsLocalDateTime(ctx).getDayOfYear();
} else if(intv.equalsIgnoreCase(INTV_DAY)) {
result = param2.getAsLocalDateTime(ctx).getDayOfMonth();
内容来源于网络,如有侵权,请联系作者删除!