Java Code Examples for java.time.LocalTime#getSecond()

The following examples show how to use java.time.LocalTime#getSecond() . 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: 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 2
Source File: PressureServiceThread.java    From game-server with MIT License 6 votes vote down vote up
@Override
public void run() {
	LocalTime localTime = LocalTime.now();
	int _sec = localTime.getSecond();
	if (sec != _sec) { // 每秒钟执行
		sec = _sec;
		HeartRequest.Builder heartBuilder = HeartRequest.newBuilder();
		player.sendUdpMsg(heartBuilder.build());
		player.getUdpSession().setAttribute(SEND_TIME, System.currentTimeMillis());
	}
	int _min = localTime.getMinute();
	if (min != _min) { // 每分钟执行
		min = _min;
		
	}
}
 
Example 3
Source File: TCKLocalizedPrinterParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    String formatted = f.format(time);
    assertEquals(formatted, text);
}
 
Example 4
Source File: TCKLocalizedPrinterParser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    TemporalAccessor parsed = f.parse(text, pos);
    assertEquals(pos.getIndex(), text.length());
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(LocalTime.from(parsed), time);
}
 
Example 5
Source File: TCKLocalizedPrinterParser.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    String formatted = f.format(time);
    assertEquals(formatted, text);
}
 
Example 6
Source File: TCKLocalizedPrinterParser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    TemporalAccessor parsed = f.parse(text, pos);
    assertEquals(pos.getIndex(), text.length());
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(LocalTime.from(parsed), time);
}
 
Example 7
Source File: BarSeriesLoader.java    From java-trader with Apache License 2.0 5 votes vote down vote up
/**
 * 返回交易时间, 131000 格式
 */
protected static int getMarketTime(LocalTime marketTime){
    if ( marketTime==null ){
        return 0;
    }
    int marketHour = marketTime.getHour();
    int marketMinute = marketTime.getMinute();
    int marketSecond = marketTime.getSecond();
    int time = marketHour*10000+marketMinute*100+marketSecond;
    return time;
}
 
Example 8
Source File: TCKLocalizedPrinterParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    String formatted = f.format(time);
    assertEquals(formatted, text);
}
 
Example 9
Source File: TCKLocalizedPrinterParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    TemporalAccessor parsed = f.parse(text, pos);
    assertEquals(pos.getIndex(), text.length());
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(LocalTime.from(parsed), time);
}
 
Example 10
Source File: TCKLocalizedPrinterParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    TemporalAccessor parsed = f.parse(text, pos);
    assertEquals(pos.getIndex(), text.length());
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(LocalTime.from(parsed), time);
}
 
Example 11
Source File: RoomTimer.java    From game-server with MIT License 5 votes vote down vote up
@Override
public void run() {
	LocalTime localTime = LocalTime.now();
	int _sec = localTime.getSecond();
	int _min = localTime.getMinute();
	int _hour = localTime.getHour();
	// 分成多个任务执行
	rooms.forEach(room -> {
		ScriptPool scriptPool = ScriptManager.getInstance().getBaseScriptEntry();

		// 鱼群刷新
           roomThread
				.execute(() -> scriptPool.executeScripts(IFishScript.class, script -> script.fishRefresh(room)));

		// 每秒执行
		if (sec != _sec) {
			sec=_sec;
               roomThread.execute(() -> scriptPool.executeScripts(IRoomScript.class,
					script -> script.secondHandler(room, localTime)));
		}
		
		//每分钟执行
		if(min!=_min) {
			min=_min;
			scriptPool.executeScripts(IRoomScript.class, script->script.minuteHandler(room, localTime));
		}
		
		if (hour != _hour) { // 每小时执行
			hour = _hour;
			scriptPool.executeScripts(IRoomScript.class, script->script.minuteHandler(room, localTime));
		}
	});

}
 
Example 12
Source File: Helper.java    From Medusa with Apache License 2.0 5 votes vote down vote up
public static final void drawTimeAreas(final Clock CLOCK, final GraphicsContext CTX, final List<TimeSection> AREAS, final double SIZE,
                                       final double XY_INSIDE, final double XY_OUTSIDE, final double WH_INSIDE, final double WH_OUTSIDE) {
    if (AREAS.isEmpty()) return;
    TickLabelLocation tickLabelLocation = CLOCK.getTickLabelLocation();
    ZonedDateTime     time              = CLOCK.getTime();
    boolean           isAM              = time.get(ChronoField.AMPM_OF_DAY) == 0;
    double            xy                = TickLabelLocation.OUTSIDE == tickLabelLocation ? XY_OUTSIDE * SIZE : XY_INSIDE * SIZE;
    double            wh                = TickLabelLocation.OUTSIDE == tickLabelLocation ? WH_OUTSIDE * SIZE : WH_INSIDE * SIZE;
    double            offset            = 90;
    double            angleStep         = 360.0 / 60.0;
    int               listSize          = AREAS.size();
    boolean           highlightAreas    = CLOCK.isHighlightAreas();
    for (int i = 0; i < listSize ; i++) {
        TimeSection area      = AREAS.get(i);
        LocalTime   start     = area.getStart();
        LocalTime   stop      = area.getStop();
        boolean     isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0;
        boolean     isStopAM  = stop.get(ChronoField.AMPM_OF_DAY) == 0;
        boolean     draw      = isAM ? (isStartAM || isStopAM) :(!isStartAM || !isStopAM);
        if (draw) {
            double areaStartAngle  = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180;;
            double areaAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep;
            //TODO: Add an indicator to the area like -1 or similar
            // check if start was already yesterday
            if (start.getHour() > stop.getHour()) { areaAngleExtend = (360.0 - Math.abs(areaAngleExtend)); }
            CTX.save();
            if (highlightAreas) {
                CTX.setFill(area.contains(time.toLocalTime()) ? area.getHighlightColor() : area.getColor());
            } else {
                CTX.setFill(area.getColor());
            }
            CTX.fillArc(xy, xy, wh, wh, -(offset + areaStartAngle), -areaAngleExtend, ArcType.ROUND);
            CTX.restore();
        }
    }
}
 
Example 13
Source File: TCKLocalizedPrinterParser.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    String formatted = f.format(time);
    assertEquals(formatted, text);
}
 
Example 14
Source File: TimerControlTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
private void drawTimeSections() {
    if (sectionMap.isEmpty()) return;
    ZonedDateTime time              = tile.getTime();
    DayOfWeek     day               = time.getDayOfWeek();
    boolean       isAM              = time.get(ChronoField.AMPM_OF_DAY) == 0;
    double        offset            = 90;
    double        angleStep         = 360.0 / 60.0;
    boolean       highlightSections = tile.isHighlightSections();
    for (TimeSection section : sectionMap.keySet()) {
        LocalTime   start     = section.getStart();
        LocalTime   stop      = section.getStop();
        boolean     isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0;
        boolean     isStopAM  = stop.get(ChronoField.AMPM_OF_DAY) == 0;
        boolean     draw      = isAM ? (isStartAM || isStopAM) : (!isStartAM || !isStopAM);
        if (!section.getDays().contains(day)) { draw = false; }
        if (!section.isActive()) { draw = false; }
        if (draw) {
            double sectionStartAngle = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180;
            double sectionAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep;
            if (start.getHour() > stop.getHour()) { sectionAngleExtend = (360.0 - Math.abs(sectionAngleExtend)); }

            Arc arc = sectionMap.get(section);
            arc.setCenterX(clockSize * 0.5);
            arc.setCenterY(clockSize * 0.5);
            arc.setRadiusX(clockSize * 0.45);
            arc.setRadiusY(clockSize * 0.45);
            arc.setStartAngle(-(offset + sectionStartAngle));
            arc.setLength(-sectionAngleExtend);
            arc.setType(ArcType.OPEN);
            arc.setStrokeWidth(clockSize * 0.04);
            arc.setStrokeLineCap(StrokeLineCap.BUTT);
            arc.setFill(null);

            if (highlightSections) {
                arc.setStroke(section.contains(time.toLocalTime()) ? section.getHighlightColor() : section.getColor());
            } else {
                arc.setStroke(section.getColor());
            }
        }
    }
}
 
Example 15
Source File: JavatimeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isEqual(LocalTime lt, java.sql.Time t) {
    return lt.getHour() == t.getHours() &&
           lt.getMinute() == t.getMinutes() &&
           lt.getSecond() == t.getSeconds();
}
 
Example 16
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 17
Source File: LocalTimeHandle.java    From alibaba-rsocket-broker with Apache License 2.0 4 votes vote down vote up
public LocalTimeHandle(LocalTime o) {
    this.hour = o.getHour();
    this.minute = o.getMinute();
    this.second = o.getSecond();
    this.nano = o.getNano();
}
 
Example 18
Source File: Time.java    From Java8CN with Apache License 2.0 2 votes vote down vote up
/**
 * Obtains an instance of {@code Time} from a {@link LocalTime} object
 * with the same hour, minute and second time value as the given
 * {@code LocalTime}.
 *
 * @param time a {@code LocalTime} to convert
 * @return a {@code Time} object
 * @exception NullPointerException if {@code time} is null
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Time valueOf(LocalTime time) {
    return new Time(time.getHour(), time.getMinute(), time.getSecond());
}
 
Example 19
Source File: Time.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Obtains an instance of {@code Time} from a {@link LocalTime} object
 * with the same hour, minute and second time value as the given
 * {@code LocalTime}.
 *
 * @param time a {@code LocalTime} to convert
 * @return a {@code Time} object
 * @exception NullPointerException if {@code time} is null
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Time valueOf(LocalTime time) {
    return new Time(time.getHour(), time.getMinute(), time.getSecond());
}
 
Example 20
Source File: Time.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * Obtains an instance of {@code Time} from a {@link LocalTime} object
 * with the same hour, minute and second time value as the given
 * {@code LocalTime}.
 *
 * @param time a {@code LocalTime} to convert
 * @return a {@code Time} object
 * @exception NullPointerException if {@code time} is null
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Time valueOf(LocalTime time) {
    return new Time(time.getHour(), time.getMinute(), time.getSecond());
}