Java Code Examples for java.time.ZonedDateTime#toLocalTime()

The following examples show how to use java.time.ZonedDateTime#toLocalTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeMetadataProvider.java    From recheck with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Map<String, String> retrieve() {
	final Map<String, String> map = new HashMap<>();

	final ZonedDateTime now = ZonedDateTime.now();
	final LocalTime time = now.toLocalTime();
	final LocalDate date = now.toLocalDate();
	final ZoneId zone = now.getZone();
	final ZoneOffset offset = now.getOffset();

	map.put( TIME, time.format( TIME_FORMATTER ) );
	map.put( DATE, date.format( DATE_FORMATTER ) );
	map.put( ZONE, zone.getId() );
	map.put( OFFSET, offset.getId() );

	return map;
}
 
Example 2
Source File: LunarExpression.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isMatchDateTime(ZonedDateTime dateTime) {
    LunarDate lunar = new LunarDate(dateTime.toLocalDate());
    int year = lunar.getYear();
    boolean leap = lunar.isLeap();
    int month = lunar.getMonth();
    int day = lunar.getDay();
    int size = LunarDate.getDaySize(year, leap, month);
    BitSet days = getDays(size);
    LocalTime time = dateTime.toLocalTime();
    int hour = time.getHour();
    int minute = time.getMinute();
    int second = time.getSecond();
    if (seconds.get(second) && minutes.get(minute) && hours.get(hour)) {
        if (days.get(day) && months.get(month) && years.get(year - LunarDate.MINIMUM_YEAR)) {
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: IslamicExpression.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isMatchDateTime(ZonedDateTime dateTime) {
    IslamicDate islamic = new IslamicDate(dateTime.toLocalDate());
    int year = islamic.getYear();
    int month = islamic.getMonth();
    int day = islamic.getDay();
    int size = IslamicDate.getDaySize(year, month);
    BitSet days = getDays(size);
    LocalTime time = dateTime.toLocalTime();
    int hour = time.getHour();
    int minute = time.getMinute();
    int second = time.getSecond();
    if (seconds.get(second) && minutes.get(minute) && hours.get(hour)) {
        if (days.get(day) && months.get(month) && years.get(year - IslamicDate.MINIMUM_YEAR)) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: TimeSlot.java    From Mutters with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<SlotMatch<LocalTime>> match(String token, Context context)
{

  Parser parser = new Parser(context.getTimeZone());

  List<DateGroup> groups = parser.parse(token);
  for (DateGroup group : groups)
  {
    if (!group.isTimeInferred())
    {
      List<Date> dates = group.getDates();

      // natty is very aggressive so will match date on text that is largely not a
      // date, which is
      // not what we want
      String matchText = group.getText();
      float percMatch = (float) matchText.length() / (float) token.length();

      if (!dates.isEmpty() && percMatch > 0.75)
      {
        ZonedDateTime theDateTime = ZonedDateTime.ofInstant(dates.get(0).toInstant(),
            context.getTimeZone().toZoneId());
        LocalTime localTime = theDateTime.toLocalTime();
        return Optional.of(new SlotMatch<>(this, token, localTime));
      }
    }
  }

  return Optional.empty();
}
 
Example 5
Source File: DateTimeConverters.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public LocalTime convert(ZonedDateTime source) {
	return source.toLocalTime();
}
 
Example 6
Source File: DateTimeConverters.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public LocalTime convert(ZonedDateTime source) {
	return source.toLocalTime();
}
 
Example 7
Source File: LunarExpression.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
@Override
public ZonedDateTime getPreviousDateTime(ZonedDateTime dateTime) {
    LunarDate lunar = new LunarDate(dateTime.toLocalDate());
    int year = lunar.getYear();
    boolean leap = lunar.isLeap();
    int month = lunar.getMonth();
    int day = lunar.getDay();
    int size = LunarDate.getDaySize(year, leap, month);
    BitSet days = getDays(size);
    LocalTime time = dateTime.toLocalTime();
    int hour = time.getHour();
    int minute = time.getMinute();
    int second = time.getSecond();
    second = seconds.previousSetBit(second - 1);
    if (second == -1) {
        second = seconds.previousSetBit(59);
        minute--;
    }
    minute = minutes.previousSetBit(minute);
    if (minute == -1) {
        second = seconds.previousSetBit(59);
        minute = minutes.previousSetBit(59);
        hour--;
    }
    hour = hours.previousSetBit(hour);
    if (hour == -1) {
        second = seconds.previousSetBit(59);
        minute = minutes.previousSetBit(59);
        hour = hours.previousSetBit(23);
        day--;
    }
    day = days.previousSetBit(day);
    if (day == -1) {
        second = seconds.previousSetBit(59);
        minute = minutes.previousSetBit(59);
        hour = hours.previousSetBit(23);
    }
    while (day == -1) {
        // 从是闰月到非闰月
        if (leap && month == LunarDate.getLeapMonth(year)) {
            leap = false;
        } else {
            month--;
            // 从非闰月到是闰月
            if (month == LunarDate.getLeapMonth(year)) {
                leap = true;
            }
        }
        // 月份是否变化
        if (!months.get(month)) {
            month = months.previousSetBit(month);
            if (month == -1) {
                month = months.previousSetBit(12);
                year--;
                year = years.previousSetBit(year - LunarDate.MINIMUM_YEAR);
                if (year == -1) {
                    return null;
                }
                year += LunarDate.MINIMUM_YEAR;
            }
            // 可能是闰月
            leap = month == LunarDate.getLeapMonth(year);
        }
        size = LunarDate.getDaySize(year, leap, month);
        days = getDays(size);
        day = days.previousSetBit(30);
    }
    if (!years.get(year - LunarDate.MINIMUM_YEAR)) {
        return null;
    }
    lunar = new LunarDate(year, leap, month, day);
    LocalDate date = lunar.getDate();
    return ZonedDateTime.of(date, LocalTime.of(hour, minute, second), dateTime.getZone());
}
 
Example 8
Source File: LunarExpression.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
@Override
public ZonedDateTime getNextDateTime(ZonedDateTime dateTime) {
    LunarDate lunar = new LunarDate(dateTime.toLocalDate());
    int year = lunar.getYear();
    boolean leap = lunar.isLeap();
    int month = lunar.getMonth();
    int day = lunar.getDay();
    int size = LunarDate.getDaySize(year, leap, month);
    BitSet days = getDays(size);
    LocalTime time = dateTime.toLocalTime();
    int hour = time.getHour();
    int minute = time.getMinute();
    int second = time.getSecond();
    second = seconds.nextSetBit(second + 1);
    if (second == -1) {
        second = seconds.nextSetBit(0);
        minute++;
    }
    minute = minutes.nextSetBit(minute);
    if (minute == -1) {
        second = seconds.nextSetBit(0);
        minute = minutes.nextSetBit(0);
        hour++;
    }
    hour = hours.nextSetBit(hour);
    if (hour == -1) {
        second = seconds.nextSetBit(0);
        minute = minutes.nextSetBit(0);
        hour = hours.nextSetBit(0);
        day++;
    }
    day = days.nextSetBit(day);
    if (day == -1) {
        second = seconds.nextSetBit(0);
        minute = minutes.nextSetBit(0);
        hour = hours.nextSetBit(0);
    }
    while (day == -1) {
        // 从非闰月到是闰月
        if (!leap && month == LunarDate.getLeapMonth(year)) {
            leap = true;
        } else {
            month++;
            leap = false;
        }
        // 月份是否变化
        if (!months.get(month)) {
            month = months.nextSetBit(month);
            if (month == -1) {
                month = months.nextSetBit(1);
                year++;
            }
            year = years.nextSetBit(year - LunarDate.MINIMUM_YEAR);
            if (year == -1) {
                return null;
            }
            year += LunarDate.MINIMUM_YEAR;
            // 一定非闰月
            leap = false;
        }
        size = LunarDate.getDaySize(year, leap, month);
        days = getDays(size);
        day = days.nextSetBit(1);
    }
    if (!years.get(year - LunarDate.MINIMUM_YEAR)) {
        return null;
    }
    lunar = new LunarDate(year, leap, month, day);
    LocalDate date = lunar.getDate();
    return ZonedDateTime.of(date, LocalTime.of(hour, minute, second), dateTime.getZone());
}
 
Example 9
Source File: IslamicExpression.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
@Override
public ZonedDateTime getPreviousDateTime(ZonedDateTime dateTime) {
    IslamicDate islamic = new IslamicDate(dateTime.toLocalDate());
    int year = islamic.getYear();
    int month = islamic.getMonth();
    int day = islamic.getDay();
    int size = IslamicDate.getDaySize(year, month);
    BitSet days = getDays(size);
    LocalTime time = dateTime.toLocalTime();
    int hour = time.getHour();
    int minute = time.getMinute();
    int second = time.getSecond();
    second = seconds.previousSetBit(second - 1);
    if (second == -1) {
        second = seconds.previousSetBit(59);
        minute--;
    }
    minute = minutes.previousSetBit(minute);
    if (minute == -1) {
        second = seconds.previousSetBit(59);
        minute = minutes.previousSetBit(59);
        hour--;
    }
    hour = hours.previousSetBit(hour);
    if (hour == -1) {
        second = seconds.previousSetBit(59);
        minute = minutes.previousSetBit(59);
        hour = hours.previousSetBit(23);
        day--;
    }
    day = days.previousSetBit(day);
    if (day == -1) {
        second = seconds.previousSetBit(59);
        minute = minutes.previousSetBit(59);
        hour = hours.previousSetBit(23);
    }
    while (day == -1) {
        month--;
        if (!months.get(month)) {
            month = months.previousSetBit(month);
            if (month == -1) {
                month = months.previousSetBit(12);
                year--;
                year = years.previousSetBit(year - IslamicDate.MINIMUM_YEAR);
                if (year == -1) {
                    return null;
                }
                year += IslamicDate.MINIMUM_YEAR;
            }
        }
        size = IslamicDate.getDaySize(year, month);
        days = getDays(size);
        day = days.previousSetBit(30);
    }
    if (!years.get(year - IslamicDate.MINIMUM_YEAR)) {
        return null;
    }
    islamic = new IslamicDate(year, month, day);
    LocalDate date = islamic.getDate();
    return ZonedDateTime.of(date, LocalTime.of(hour, minute, second), dateTime.getZone());
}
 
Example 10
Source File: IslamicExpression.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
@Override
public ZonedDateTime getNextDateTime(ZonedDateTime dateTime) {
    IslamicDate islamic = new IslamicDate(dateTime.toLocalDate());
    int year = islamic.getYear();
    int month = islamic.getMonth();
    int day = islamic.getDay();
    int size = IslamicDate.getDaySize(year, month);
    BitSet days = getDays(size);
    LocalTime time = dateTime.toLocalTime();
    int hour = time.getHour();
    int minute = time.getMinute();
    int second = time.getSecond();
    second = seconds.nextSetBit(second + 1);
    if (second == -1) {
        second = seconds.nextSetBit(0);
        minute++;
    }
    minute = minutes.nextSetBit(minute);
    if (minute == -1) {
        second = seconds.nextSetBit(0);
        minute = minutes.nextSetBit(0);
        hour++;
    }
    hour = hours.nextSetBit(hour);
    if (hour == -1) {
        second = seconds.nextSetBit(0);
        minute = minutes.nextSetBit(0);
        hour = hours.nextSetBit(0);
        day++;
    }
    day = days.nextSetBit(day);
    if (day == -1) {
        second = seconds.nextSetBit(0);
        minute = minutes.nextSetBit(0);
        hour = hours.nextSetBit(0);
    }
    while (day == -1) {
        month++;
        if (!months.get(month)) {
            month = months.nextSetBit(month);
            if (month == -1) {
                month = months.nextSetBit(1);
                year++;
            }
            year = years.nextSetBit(year - IslamicDate.MINIMUM_YEAR);
            if (year == -1) {
                return null;
            }
            year += IslamicDate.MINIMUM_YEAR;
        }
        size = IslamicDate.getDaySize(year, month);
        days = getDays(size);
        day = days.nextSetBit(1);
    }
    if (!years.get(year - IslamicDate.MINIMUM_YEAR)) {
        return null;
    }
    islamic = new IslamicDate(year, month, day);
    LocalDate date = islamic.getDate();
    return ZonedDateTime.of(date, LocalTime.of(hour, minute, second), dateTime.getZone());
}
 
Example 11
Source File: DateTimeConverters.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public LocalTime convert(ZonedDateTime source) {
	return source.toLocalTime();
}
 
Example 12
Source File: DateTimeConverters.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public LocalTime convert(ZonedDateTime source) {
	return source.toLocalTime();
}
 
Example 13
Source File: DailyReport.java    From blynk-server with GNU General Public License v3.0 4 votes vote down vote up
public void addReportSpecificAtTime(StringBuilder sb, ZoneId zoneId) {
    ZonedDateTime zonedAt = getZonedFromTs(atTime, zoneId);
    LocalTime localTime = zonedAt.toLocalTime();
    sb.append(", ").append("at ").append(LocalTime.of(localTime.getHour(), localTime.getMinute()));
}
 
Example 14
Source File: DateTimeUtility.java    From sailfish-core with Apache License 2.0 2 votes vote down vote up
/**
 * Convert TemporalAccessor to LocalTime
 * 
 * @param date
 * @return LocalTime (UTC)
 */
public static LocalTime toLocalTime(TemporalAccessor temporal) {
    ZonedDateTime zonedDateTime = toZonedDateTime(temporal);
    return zonedDateTime.toLocalTime();
}