本文整理了Java中org.joda.time.DateTime.withHourOfDay()
方法的一些代码示例,展示了DateTime.withHourOfDay()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTime.withHourOfDay()
方法的具体详情如下:
包路径:org.joda.time.DateTime
类名称:DateTime
方法名:withHourOfDay
[英]Returns a copy of this datetime with the hour of day field updated.
DateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of hour of day changed.
[中]返回此datetime的副本,其中“小时”字段已更新。
DateTime是不可变的,因此没有set方法。相反,此方法返回一个值为hour of day的新实例。
代码示例来源:origin: azkaban/azkaban
private DateTime parseDateTime(final String scheduleDate, final String scheduleTime) {
// scheduleTime: 12,00,pm,PDT
final String[] parts = scheduleTime.split(",", -1);
int hour = Integer.parseInt(parts[0]);
final int minutes = Integer.parseInt(parts[1]);
final boolean isPm = parts[2].equalsIgnoreCase("pm");
final DateTimeZone timezone =
parts[3].equals("UTC") ? DateTimeZone.UTC : DateTimeZone.getDefault();
// scheduleDate: 02/10/2013
DateTime day = null;
if (scheduleDate == null || scheduleDate.trim().length() == 0) {
day = new LocalDateTime().toDateTime();
} else {
day = DateTimeFormat.forPattern("MM/dd/yyyy")
.withZone(timezone).parseDateTime(scheduleDate);
}
hour %= 12;
if (isPm) {
hour += 12;
}
final DateTime firstSchedTime =
day.withHourOfDay(hour).withMinuteOfHour(minutes).withSecondOfMinute(0);
return firstSchedTime;
}
代码示例来源:origin: apache/incubator-pinot
case HOURS:
_dateTimeTruncate = (dateTime) -> _outputDateTimeFormatter
.print(dateTime.withHourOfDay((dateTime.getHourOfDay() / sz) * sz).hourOfDay().roundFloorCopy());
break;
case DAYS:
代码示例来源:origin: kairosdb/kairosdb
case MINUTES:
case SECONDS:
dt = dt.withHourOfDay(0);
dt = dt.withMinuteOfHour(0);
dt = dt.withSecondOfMinute(0);
代码示例来源:origin: rackerlabs/blueflood
private DateTime extractAndUpdateTime(DateTime inputDateTime) {
DateTime resultDateTime = inputDateTime.withSecondOfMinute(0).withMillisOfSecond(0);
if (dateTime.equals("") || dateTime.contains("now"))
return resultDateTime;
int hour = 0;
int minute = 0;
Pattern p = Pattern.compile("(\\d{1,2}):(\\d{2})([a|p]m)?(.*)");
Matcher m = p.matcher(dateTime);
if (m.matches()) {
hour = Integer.parseInt(m.group(1));
minute = Integer.parseInt(m.group(2));
String middayModifier = m.group(3);
if (middayModifier != null && middayModifier.equals("pm"))
hour = (hour + 12) % 24;
dateTime = m.group(4);
}
if (dateTime.contains("noon")) {
hour = 12;
dateTime = dateTime.replace("noon", "");
}
else if (dateTime.contains("teatime")) {
hour = 16;
dateTime = dateTime.replace("teatime", "");
} else if (dateTime.contains("midnight"))
dateTime = dateTime.replace("midnight", "");
return resultDateTime.withHourOfDay(hour).withMinuteOfHour(minute);
}
代码示例来源:origin: prestodb/presto
assertFunction("date_trunc('hour', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));
result = result.withHourOfDay(0);
assertFunction("date_trunc('day', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));
assertFunction("date_trunc('hour', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));
result = result.withHourOfDay(0);
assertFunction("date_trunc('day', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));
代码示例来源:origin: rackerlabs/blueflood
@Test
public void testHourMinuteKeywords() {
String noonTimestamp = "noon";
String teatimeTimestamp = "teatime";
String midnightTimestamp = "midnight";
Assert.assertEquals(DateTimeParser.parse(noonTimestamp),
referenceDateTime().withHourOfDay(12).withMinuteOfHour(0));
Assert.assertEquals(DateTimeParser.parse(teatimeTimestamp),
referenceDateTime().withHourOfDay(16).withMinuteOfHour(0));
Assert.assertEquals(DateTimeParser.parse(midnightTimestamp),
referenceDateTime().withHourOfDay(0).withMinuteOfHour(0));
}
代码示例来源:origin: rackerlabs/blueflood
private static DateTime referenceDateTime() {
return new DateTime().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0);
}
代码示例来源:origin: rackerlabs/blueflood
@Test
public void testRegularHourMinute() {
String hourMinuteTimestamp = "12:24";
String hourMinuteWithAm = "9:13am";
String hourMinuteWithPm = "09:13pm";
Assert.assertEquals(DateTimeParser.parse(hourMinuteTimestamp),
referenceDateTime().withHourOfDay(12).withMinuteOfHour(24));
Assert.assertEquals(DateTimeParser.parse(hourMinuteWithAm),
referenceDateTime().withHourOfDay(9).withMinuteOfHour(13));
Assert.assertEquals(DateTimeParser.parse(hourMinuteWithPm),
referenceDateTime().withHourOfDay(21).withMinuteOfHour(13));
}
代码示例来源:origin: rackerlabs/blueflood
@Test
public void testComplexFormats() {
testFormat("12:24 yesterday", nowDateTime().minusDays(1).withHourOfDay(12).withMinuteOfHour(24));
testFormat("12:24 tomorrow", nowDateTime().plusDays(1).withHourOfDay(12).withMinuteOfHour(24));
testFormat("12:24 today", nowDateTime().withHourOfDay(12).withMinuteOfHour(24));
testFormat("noon 12/30/2014", nowDateTime().withDate(2014, 12, 30).withHourOfDay(12).withMinuteOfHour(0));
int currentYear = referenceDateTime().getYear();
testFormat("15:45 12/30/14", new DateTime(2014, 12, 30, 15, 45, 0, 0));
testFormat("teatime 12/30/2014", new DateTime(2014, 12, 30, 16, 0, 0, 0));
testFormat("midnight Jul 30", new DateTime(currentYear, 07, 30, 0, 0, 0, 0));
testFormat("Jul 30, 2013", new DateTime(2013, 07, 30, 0, 0, 0, 0));
testFormat("Jul 30", new DateTime(currentYear, 07, 30, 0, 0, 0, 0));
testFormat("20141230", new DateTime(2014, 12, 30, 0, 0, 0, 0));
}
代码示例来源:origin: stackoverflow.com
DateTimeFormatter formatter = DateTimeFormat.forPattern( "dd/MM/yyyy" ); // Usually I specify a Locale as well. But in this case, no need (no names of days or months).
DateTimeZone customerTimeZone = DateTimeZone.UTC;
String input = "25/05/2014";
DateTime customerDateTime = formatter.withZone( customerTimeZone ).parseDateTime( input );
DateTime customerDateTimeAtFive = customerDateTime.withHourOfDay( 5 ); // Using customerTimeZone.
代码示例来源:origin: stackoverflow.com
DateTime dt = new DateTime(DateTimeZone.forID("US/Eastern"));
DateTime target = dt
.withHourOfDay(15)
.withMinuteOfHour(0)
.withSecondOfMinute(0)
.withMillisOfSecond(0);
if (target.isBefore(dt)) {
target = target.plusDays(1);
}
System.out.println(target.getMillis() - dt.getMillis());
代码示例来源:origin: qcadoo/mes
private Interval extractSearchInterval(final Entity contextEntity) {
Date from = contextEntity.getDateField(BalanceContextFields.FROM_DATE);
Date to = contextEntity.getDateField(BalanceContextFields.TO_DATE);
DateTime toMidnight = new DateTime(to).withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59);
return new Interval(new DateTime(from), toMidnight);
}
代码示例来源:origin: apiman/apiman
/**
* Parse the to date query param.
*/
private DateTime parseFromDate(String fromDate) {
// Default to the last 30 days
DateTime defaultFrom = new DateTime().withZone(DateTimeZone.UTC).minusDays(30).withHourOfDay(0)
.withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0);
return parseDate(fromDate, defaultFrom, true);
}
代码示例来源:origin: io.apiman/apiman-manager-api-rest-impl
/**
* Parse the to date query param.
*/
private DateTime parseFromDate(String fromDate) {
// Default to the last 30 days
DateTime defaultFrom = new DateTime().withZone(DateTimeZone.UTC).minusDays(30).withHourOfDay(0)
.withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0);
return parseDate(fromDate, defaultFrom, true);
}
代码示例来源:origin: qcadoo/mes
private Optional<DateTime> getShiftEndDate(DateTime day, Entity shift) {
Shift shiftFirst = new Shift(shift);
List<TimeRange> ranges = shiftFirst.findWorkTimeAt(day.toLocalDate());
if (ranges.isEmpty()) {
return Optional.empty();
}
LocalTime startTime = ranges.get(0).getTo();
DateTime startShitTime = day;
startShitTime = startShitTime.withHourOfDay(startTime.getHourOfDay());
startShitTime = startShitTime.withMinuteOfHour(startTime.getMinuteOfHour());
return Optional.of(startShitTime);
}
代码示例来源:origin: qcadoo/mes
private Optional<DateTime> getShiftStartDate(DateTime day, Entity shift) {
Shift shiftFirst = new Shift(shift);
List<TimeRange> ranges = shiftFirst.findWorkTimeAt(day.toLocalDate());
if (ranges.isEmpty()) {
return Optional.empty();
}
LocalTime startTime = ranges.get(0).getFrom();
DateTime startShitTime = day;
startShitTime = startShitTime.withHourOfDay(startTime.getHourOfDay());
startShitTime = startShitTime.withMinuteOfHour(startTime.getMinuteOfHour());
return Optional.of(startShitTime);
}
代码示例来源:origin: org.jasig.portlet/blackboardvc-portlet-api
@Future
public DateTime getEndTime() {
return endDate.toDateTime().withHourOfDay(endHourMinute.getHourOfDay()).withMinuteOfHour(endHourMinute.getMinuteOfHour());
}
代码示例来源:origin: blocoio/faker
private DateTime randomTime(DateTime dateTime, Period period) {
return dateTime.withHourOfDay(hours(period))
.withMinuteOfHour(minutes())
.withSecondOfMinute(seconds());
}
代码示例来源:origin: org.springframework.cloud.stream.app/app-starters-common-analytics
private long[] getMinCountsForHour(String name, int year, int month, int day, int hour) {
DateTime dt = new DateTime().withYear(year).withMonthOfYear(month).withDayOfMonth(day).withHourOfDay(hour);
AggregateKeyGenerator akg = new AggregateKeyGenerator(REPO_PREFIX, name, dt);
return convertToArray(getEntries(akg.getHourKey()), 60, false);
}
代码示例来源:origin: org.jasig.portlet/blackboardvc-portlet-api
@Future
@FutureWithYearLimit()
public DateTime getStartTime() {
return startDate.toDateTime().withHourOfDay(startHourMinute.getHourOfDay()).withMinuteOfHour(startHourMinute.getMinuteOfHour());
}
内容来源于网络,如有侵权,请联系作者删除!