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

The following examples show how to use java.time.LocalTime#format() . 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: ReportButtonPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private String getLoginTime()
{
	if (loginTime == null)
	{
		return "Report";
	}

	Duration duration = Duration.between(loginTime, Instant.now());
	LocalTime time = LocalTime.ofSecondOfDay(duration.getSeconds());
	return time.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
}
 
Example 2
Source File: CubaTimeField.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected String formatValue(LocalTime value) {
    if (value == null) {
        return "";
    }

    DateTimeFormatter dateTimeFormatter = getDateTimeFormatter();
    return value.format(dateTimeFormatter);
}
 
Example 3
Source File: PrayerPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
String getEstimatedTimeRemaining(boolean formatForOrb)
{
	final double drainRate = getPrayerDrainRate(client);

	if (drainRate == 0)
	{
		return "N/A";
	}

	final int currentPrayer = client.getBoostedSkillLevel(Skill.PRAYER);

	// Calculate how many seconds each prayer points last so the prayer bonus can be applied
	final double secondsPerPoint = (60.0 / drainRate) * (1.0 + (prayerBonus / 30.0));

	// Calculate the number of seconds left
	final double secondsLeft = (currentPrayer * secondsPerPoint);

	LocalTime timeLeft = LocalTime.ofSecondOfDay((long) secondsLeft);

	if (formatForOrb && timeLeft.getMinute() > 9)
	{
		return timeLeft.format(DateTimeFormatter.ofPattern("m")) + "m";
	}
	else
	{
		return timeLeft.format(DateTimeFormatter.ofPattern("m:ss"));
	}
}
 
Example 4
Source File: PrayerPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
String getEstimatedTimeRemaining(boolean formatForOrb)
{
	final double drainRate = getPrayerDrainRate(client);

	if (drainRate == 0)
	{
		return "N/A";
	}

	final int currentPrayer = client.getBoostedSkillLevel(Skill.PRAYER);

	// Calculate how many seconds each prayer points last so the prayer bonus can be applied
	final double secondsPerPoint = (60.0 / drainRate) * (1.0 + (prayerBonus / 30.0));

	// Calculate the number of seconds left
	final double secondsLeft = (currentPrayer * secondsPerPoint);

	LocalTime timeLeft = LocalTime.ofSecondOfDay((long) secondsLeft);

	if (formatForOrb && timeLeft.getMinute() > 9)
	{
		return timeLeft.format(DateTimeFormatter.ofPattern("m")) + "m";
	}
	else
	{
		return timeLeft.format(DateTimeFormatter.ofPattern("m:ss"));
	}
}
 
Example 5
Source File: ReportButtonPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getLoginTime()
{
	if (loginTime == null)
	{
		return "Report";
	}

	Duration duration = Duration.between(loginTime, Instant.now());
	LocalTime time = LocalTime.ofSecondOfDay(duration.getSeconds());
	return time.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
}
 
Example 6
Source File: Timer.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private static String formatTime(LocalTime time)
{
	if (time.getHour() > 0)
	{
		return time.format(DateTimeFormatter.ofPattern("HH:mm"));
	}
	else if (time.getMinute() > 9)
	{
		return time.format(DateTimeFormatter.ofPattern("mm:ss"));
	}
	else
	{
		return time.format(DateTimeFormatter.ofPattern("m:ss"));
	}
}
 
Example 7
Source File: TimeTypeAdapter.java    From jsonstream with Apache License 2.0 4 votes vote down vote up
@Override
public String serialize(LocalTime t) {
    return t.format(this.formatter);
}
 
Example 8
Source File: TemplateMaker.java    From axelor-open-suite with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public String toString(Object o, String formatString, Locale locale) {
  if (formatString == null) return o.toString();
  LocalTime ld = (LocalTime) o;
  return ld.format(DateTimeFormatter.ofPattern(formatString));
}
 
Example 9
Source File: ReportButtonPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private String getUTCTime()
{
	LocalTime time = LocalTime.now(UTC);
	return time.format(timeFormat);
}
 
Example 10
Source File: ConstExecutor.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private static TimeString toTimeString(long epoch) {
  LocalTime localTime = LocalTime.ofNanoOfDay(java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(epoch));

  return new TimeString(localTime.format(DateTimes.CALCITE_LOCAL_TIME_FORMATTER));
}
 
Example 11
Source File: LocalTimeFormatter.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public String describe(final LocalTime temporal) {
	return temporal.format(DATE_TIME_FORMAT);
}
 
Example 12
Source File: TypeConverter.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public static String getString(LocalTime value) {
    DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_TIME;
    return value.format(formatter);
}
 
Example 13
Source File: CustomConverterTest.java    From easy-excel with MIT License 4 votes vote down vote up
@Override
public String to(LocalTime localDate) {
  return localDate.format(formatter);
}
 
Example 14
Source File: ReportButtonPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private String getJagexTime()
{
	LocalTime time = LocalTime.now(JAGEX);
	return time.format(timeFormat);
}
 
Example 15
Source File: ReportButtonPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private String getUTCTime()
{
	LocalTime time = LocalTime.now(UTC);
	return time.format(timeFormat);
}
 
Example 16
Source File: DateUtils.java    From Raincat with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 将localDateTime 格式化成特定格式的字符串.
 *
 * @param time       时间
 * @param dateFormat 格式化
 * @return String string
 */
public static String formaterTime(final LocalTime time, final String dateFormat) {
    return time.format(DateTimeFormatter.ofPattern(dateFormat));
}
 
Example 17
Source File: LocalTimeConverter.java    From library with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc }
 *
 * @param context
 * @param component
 * @param value
 * @return
 */
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
    final LocalTime time = (LocalTime) value;
    return time.format(DateTimeFormatter.ofPattern("HH:mm"));
}
 
Example 18
Source File: DateTimeExtensions.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * Formats this time with the {@link java.time.format.DateTimeFormatter#ISO_LOCAL_TIME} formatter.
 *
 * @param self a LocalTime
 * @return a formatted String
 * @see java.time.format.DateTimeFormatter
 * @since 2.5.0
 */
public static String getTimeString(final LocalTime self) {
    return self.format(DateTimeFormatter.ISO_LOCAL_TIME);
}
 
Example 19
Source File: LocalTimeConverter.java    From web-budget with GNU General Public License v3.0 2 votes vote down vote up
/**
 * {@inheritDoc }
 *
 * @param context
 * @param component
 * @param value
 * @return
 */
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
    final LocalTime time = (LocalTime) value;
    return time.format(DateTimeFormatter.ofPattern("HH:mm"));
}
 
Example 20
Source File: DateTimeExtensions.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * Formats this time in the provided, localized {@link java.time.format.FormatStyle}.
 *
 * @param self      a LocalTime
 * @param timeStyle the FormatStyle
 * @return a formatted String
 * @see java.time.format.DateTimeFormatter
 * @since 2.5.0
 */
public static String format(final LocalTime self, FormatStyle timeStyle) {
    return self.format(DateTimeFormatter.ofLocalizedTime(timeStyle));
}