org.joda.time.LocalTime.toDateTime()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(343)

本文整理了Java中org.joda.time.LocalTime.toDateTime()方法的一些代码示例,展示了LocalTime.toDateTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalTime.toDateTime()方法的具体详情如下:
包路径:org.joda.time.LocalTime
类名称:LocalTime
方法名:toDateTime

LocalTime.toDateTime介绍

[英]Converts this LocalTime to a full datetime using the default time zone setting the time fields from this instance and the date fields from the current date.
[中]使用默认时区设置此实例的时间字段和当前日期的日期字段,将此LocalTime转换为完整日期时间。

代码示例

代码示例来源:origin: prestodb/presto

  1. return new LocalDate(2001, 8, 22).toDateMidnight(DateTimeZone.UTC).getMillis();
  2. case "bound_time":
  3. return new LocalTime(3, 4, 5, 321).toDateTime(new DateTime(0, DateTimeZone.UTC)).getMillis();
  4. case "bound_timestamp":
  5. return new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC).getMillis();

代码示例来源:origin: stackoverflow.com

  1. LocalTime localTime = new LocalTime( 13 , 15 ); // Quarter-hour after 1 PM.
  2. System.out.println( "localTime: " + localTime );
  3. DateTimeZone timeZone = DateTimeZone.forID( "America/Montreal" ); // Or DateTimeZone.UTC
  4. DateTime today = localTime.toDateTimeToday( timeZone );
  5. DateTime now = DateTime.now(); // You may want to pad an bit of extra time in case now is extremely close to midnight (new day).
  6. if ( today.isBefore( now ) ) {
  7. // If the local time in question when applied to today has already past, then
  8. // adjust to tomorrow while accounting for Daylight Saving Time or other anomaly.
  9. DateTime tomorrowInitial = today.plusDays( 1 ); // Get tomorrow by adding 1 day to today.
  10. DateTime tomorrow = localTime.toDateTime( tomorrowInitial ); // DST or other anomaly may mean that tomorrow got adjusted to a different time-of-day. Override with our desired time-of-day.
  11. System.out.println( "tomorrow: " + tomorrow );
  12. // return tomorrow;
  13. }
  14. System.out.println( "today: " + today );
  15. // return today;

代码示例来源:origin: qcadoo/mes

  1. public DateTimeRange(final DateTime day, final TimeRange range) {
  2. DateTime from;
  3. DateTime to;
  4. if (range.startsDayBefore()) {
  5. to = range.getTo().toDateTime(day.plusDays(1));
  6. } else {
  7. to = range.getTo().toDateTime(day);
  8. }
  9. from = range.getFrom().toDateTime(day);
  10. interval = new Interval(from, to);
  11. }

代码示例来源:origin: apiman/apiman

  1. /**
  2. * Returns true if the given DateTime matches the time range indicated by the
  3. * filter/rule.
  4. * @param currentTime
  5. * @param filter
  6. */
  7. private boolean matchesTime(TimeRestrictedAccess filter) {
  8. Date start = filter.getTimeStart();
  9. Date end = filter.getTimeEnd();
  10. if (end == null || start == null) {
  11. return true;
  12. }
  13. long startMs = start.getTime();
  14. long endMs = end.getTime();
  15. DateTime currentTime = new LocalTime(DateTimeZone.UTC).toDateTime(new DateTime(0l));
  16. long nowMs = currentTime.toDate().getTime();
  17. return nowMs >= startMs && nowMs < endMs;
  18. }

代码示例来源:origin: Jasig/uPortal

  1. @Override
  2. public DateTime getDateTime() {
  3. DateTime dt = this.dateTime;
  4. if (dt == null) {
  5. dt = this.timeDimension.getTime().toDateTime(this.dateDimension.getDate());
  6. this.dateTime = dt;
  7. }
  8. return dt;
  9. }

代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl

  1. public void setActionTime(String actionTime) {
  2. if (StringUtils.isNotBlank(actionTime)) {
  3. setLocalTime(actionTime != null ? FORMATTER.parseLocalTime(actionTime) : null);
  4. if (localDate != null
  5. && localTime != null) {
  6. actionDateTime = localTime.toDateTime(localDate.toDateTimeAtStartOfDay()).toDate();
  7. }
  8. }
  9. }

代码示例来源:origin: org.actframework/act-morphia

  1. @Override
  2. public Object encode(Object value, MappedField optionalExtraInfo) {
  3. if (null == value) {
  4. return null;
  5. }
  6. if (value instanceof DateTime) {
  7. DateTime dateTime = (DateTime) value;
  8. return dateTime.getMillis();
  9. } else if (value instanceof LocalDateTime) {
  10. LocalDateTime localDateTime = (LocalDateTime) value;
  11. return localDateTime.toDateTime().getMillis();
  12. } else if (value instanceof LocalDate) {
  13. LocalDate localDate = (LocalDate) value;
  14. return localDate.toDateTimeAtStartOfDay().getMillis();
  15. } else if (value instanceof LocalTime) {
  16. LocalTime localTime = (LocalTime) value;
  17. return localTime.toDateTime(new DateTime(0)).getMillis();
  18. } else {
  19. assert false;
  20. return null;
  21. }
  22. }

代码示例来源:origin: qcadoo/mes

  1. private DateRange buildDateRangeFrom(final TimeRange timeRange, final Date date) {
  2. DateTime dateTime = new DateTime(date);
  3. DateTime midnight = dateTime.withTimeAtStartOfDay();
  4. DateTime from;
  5. DateTime to;
  6. if (timeRange.startsDayBefore()) {
  7. if (dateTime.toLocalTime().isBefore(timeRange.getFrom())) {
  8. from = timeRange.getFrom().toDateTime(midnight.minusDays(1));
  9. to = timeRange.getTo().toDateTime(midnight);
  10. } else {
  11. from = timeRange.getFrom().toDateTime(midnight);
  12. to = timeRange.getTo().toDateTime(midnight.plusDays(1));
  13. }
  14. } else {
  15. from = timeRange.getFrom().toDateTime(midnight);
  16. to = timeRange.getTo().toDateTime(midnight);
  17. }
  18. return new DateRange(from.toDate(), to.toDate());
  19. }

代码示例来源:origin: stackoverflow.com

  1. import org.joda.time.DateTime;
  2. import org.joda.time.DateTimeConstants;
  3. import org.joda.time.Interval;
  4. import org.joda.time.LocalTime;
  5. public class Main {
  6. public static void main(String[] args) {
  7. Interval interval = betweenNowAndNext(DateTimeConstants.MONDAY, new LocalTime(10, 14));
  8. System.out.println(interval.toDurationMillis());
  9. }
  10. public static Interval betweenNowAndNext(int dayOfWeek, LocalTime time) {
  11. DateTime now = DateTime.now();
  12. DateTime closest = time.toDateTime(now).withDayOfWeek(dayOfWeek);
  13. return new Interval(now, closest.isBefore(now) ? closest.plusWeeks(1) : closest);
  14. }
  15. }

代码示例来源:origin: stackoverflow.com

  1. this(from == null ? null : from.toDateTime(INSTANT),
  2. to == null ? null : to.toDateTime(INSTANT));

代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl

  1. protected List<Shift> createShifts(ShiftDifferentialRule rule, LocalDateTime spanBegin, LocalDateTime spanEnd, DateTimeZone zone) {
  2. DateTime spanBeginDT = spanBegin.toDateTime(zone);
  3. DateTime spanEndDT = spanEnd.toDateTime(zone);
  4. Interval calendarEntryInterval = new Interval(spanBeginDT, spanEndDT);
  5. DateTime shiftEnd = LocalTime.fromDateFields(rule.getEndTime()).toDateTime(spanBeginDT).minusDays(1);
  6. DateTime shiftStart = LocalTime.fromDateFields(rule.getBeginTime()).toDateTime(spanBeginDT).minusDays(1);
  7. if (shiftEnd.isBefore(shiftStart) || shiftEnd.isEqual(shiftStart)) {
  8. shiftEnd = shiftEnd.plusDays(1);
  9. }
  10. List<Shift> shifts = new ArrayList<Shift>();
  11. Interval shiftInterval = new Interval(shiftStart, shiftEnd);
  12. //possible that there is no overlap between 1st interval and cal entry interval... if so, add a day.
  13. if (!calendarEntryInterval.overlaps(shiftInterval)) {
  14. shiftInterval = incrementShift(shiftInterval);
  15. }
  16. while (calendarEntryInterval.overlaps(shiftInterval)) {
  17. if (ruleIsActiveForDay(shiftInterval.getStart(), rule)) {
  18. shifts.add(new Shift(rule, shiftInterval, zone));
  19. }
  20. shiftInterval = incrementShift(shiftInterval);
  21. }
  22. return shifts;
  23. }

代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl

  1. LocalTime ruleEnd = new LocalTime(rule.getEndTime());
  2. DateTime beginShiftEnd = ruleEnd.toDateTime(calEntryBegin.minusDays(1));
  3. DateTime beginShiftStart = ruleStart.toDateTime(calEntryBegin.minusDays(1));
  4. DateTime endShiftEnd = ruleEnd.toDateTime(calEntryEnd);
  5. DateTime endShiftBegin = ruleStart.toDateTime(calEntryEnd);

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

  1. @Override
  2. public Object getValue(Symbol symbol)
  3. {
  4. switch (symbol.getName().toLowerCase(ENGLISH)) {
  5. case "bound_long":
  6. return 1234L;
  7. case "bound_string":
  8. return utf8Slice("hello");
  9. case "bound_double":
  10. return 12.34;
  11. case "bound_date":
  12. return new LocalDate(2001, 8, 22).toDateMidnight(DateTimeZone.UTC).getMillis();
  13. case "bound_time":
  14. return new LocalTime(3, 4, 5, 321).toDateTime(new DateTime(0, DateTimeZone.UTC)).getMillis();
  15. case "bound_timestamp":
  16. return new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC).getMillis();
  17. case "bound_pattern":
  18. return utf8Slice("%el%");
  19. case "bound_timestamp_with_timezone":
  20. return new SqlTimestampWithTimeZone(new DateTime(1970, 1, 1, 1, 0, 0, 999, DateTimeZone.UTC).getMillis(), getTimeZoneKey("Z"));
  21. case "bound_varbinary":
  22. return Slices.wrappedBuffer((byte) 0xab);
  23. }
  24. return new QualifiedNameReference(symbol.toQualifiedName());
  25. }
  26. });

代码示例来源:origin: com.sap.cloud.s4hana.datamodel/odata-core

  1. } else if( comparisonValue instanceof org.joda.time.LocalTime ) {
  2. final Date date =
  3. ((org.joda.time.LocalTime) comparisonValue).toDateTime(new DateTime(0, DateTimeZone.UTC)).toDate();
  4. odataExpr = new FilterExpression(fieldName, function, ODataType.of(date));
  5. } else if( comparisonValue instanceof org.joda.time.LocalDateTime ) {

代码示例来源:origin: io.prestosql/presto-main

  1. return new LocalDate(2001, 8, 22).toDateMidnight(DateTimeZone.UTC).getMillis();
  2. case "bound_time":
  3. return new LocalTime(3, 4, 5, 321).toDateTime(new DateTime(0, DateTimeZone.UTC)).getMillis();
  4. case "bound_timestamp":
  5. return new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC).getMillis();

代码示例来源:origin: prestosql/presto

  1. return new LocalDate(2001, 8, 22).toDateMidnight(DateTimeZone.UTC).getMillis();
  2. case "bound_time":
  3. return new LocalTime(3, 4, 5, 321).toDateTime(new DateTime(0, DateTimeZone.UTC)).getMillis();
  4. case "bound_timestamp":
  5. return new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC).getMillis();

相关文章