作者:形同陌路2502906543 | 来源:互联网 | 2023-08-18 11:46
本文整理了Java中org.opennms.core.time.ZonedDateTimeBuilder
类的一些代码示例,展示了ZonedDateTimeBuilder
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTimeBuilder
类的具体详情如下:
包路径:org.opennms.core.time.ZonedDateTimeBuilder
类名称:ZonedDateTimeBuilder
ZonedDateTimeBuilder介绍
[英]This is basically a Calendar.Builder replacement that builds Java 8 ZonedDateTime instances.
[中]这基本上是一个日历。构建器替换,用于构建Java 8 ZoneDateTime实例。
代码示例
代码示例来源:origin: OpenNMS/opennms
/**
* If some fields have not been set,
* intelligently set them so that we generate a observed
* datestamp that is less than or slightly greater than
* {@link System#currentTimeMillis()} (due to clock skew).
* For instance, around midnight on Dec 31, 2017, we do not
* want to generate datestamps of Dec 31, 2018 at the instant
* that {@link LocalDateTime#now()} starts returning a
* January 1, 2018 datestamp.
*
* @return
*/
protected int getBestYear() {
if (m_year == null) {
return getBestYearForMonth(m_month);
} else {
return m_year;
}
}
代码示例来源:origin: OpenNMS/opennms
protected ZonedDateTimeBuilder getZonedDateTimeBuilder() {
if (zOnedDateTimeBuilder== null) {
zOnedDateTimeBuilder= new ZonedDateTimeBuilder();
}
return zonedDateTimeBuilder;
}
代码示例来源:origin: OpenNMS/opennms
if (m_second != null) {
if (m_nanosecond != null) {
return ZonedDateTime.of(getBestYear(), m_month, m_dayOfMonth, m_hourOfDay == null ? 0 : m_hourOfDay, m_minute, m_second, m_nanosecond, getBestZoneId());
} else {
return ZonedDateTime.of(getBestYear(), m_month, m_dayOfMonth, m_hourOfDay, m_minute, m_second, 0, getBestZoneId());
return ZonedDateTime.of(getBestYear(), m_month, m_dayOfMonth, m_hourOfDay, m_minute, 0, 0, getBestZoneId());
return ZonedDateTime.of(getBestYear(), m_month, m_dayOfMonth, m_hourOfDay, 0, 0, 0, getBestZoneId());
return ZonedDateTime.of(getBestYear(), m_month, m_dayOfMonth, 0, 0, 0, 0, getBestZoneId());
代码示例来源:origin: OpenNMS/opennms
public Date currentEventTime() {
if (m_event.getTime() == null && zonedDateTimeBuilder != null) {
ZonedDateTime time = zonedDateTimeBuilder.build();
return Date.from(time.toInstant());
} else {
return m_event.getTime();
}
}
代码示例来源:origin: OpenNMS/opennms
public EventBuilder setMonth(final int value) {
// Note that java.time.Month values are 1-based
// unlike java.util.Calendar.MONTH values which
// are zero-based
getZonedDateTimeBuilder().setMonth(value);
return this;
}
代码示例来源:origin: OpenNMS/opennms
public EventBuilder setDayOfMonth(final int value) {
getZonedDateTimeBuilder().setDayOfMonth(value);
return this;
}
代码示例来源:origin: OpenNMS/opennms
public EventBuilder setMinute(final int value) {
getZonedDateTimeBuilder().setMinute(value);
return this;
}
代码示例来源:origin: OpenNMS/opennms
public EventBuilder setHourOfDay(final int value) {
getZonedDateTimeBuilder().setHourOfDay(value);
return this;
}
代码示例来源:origin: OpenNMS/opennms
case timezone:
return (s,v) -> {
s.message.setZoneId(ZonedDateTimeBuilder.parseZoneId(v));
};
default:
代码示例来源:origin: OpenNMS/opennms
/**
* getEvent
*
* @return a {@link org.opennms.netmgt.xml.event.Event} object.
*/
public Event getEvent() {
if (m_event.getTime() == null && zonedDateTimeBuilder != null) {
ZonedDateTime time = zonedDateTimeBuilder.build();
m_event.setTime(Date.from(time.toInstant()));
}
if (m_event.getCreationTime() == null) {
// The creation time has been used as the time when the event
// is stored in the database so update it right before we return
// the event object.
m_event.setCreationTime(new Date());
}
return m_event;
}
代码示例来源:origin: OpenNMS/opennms
protected Date parseDate(final String dateString) {
try {
// Date pattern has been created and checked inside if loop instead of
// parsing date inside the exception class.
if (dateString.matches(datePattern)) {
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
adjustTimeZone(df);
return df.parse(dateString);
} else {
final DateFormat df = new SimpleDateFormat("MMM dd HH:mm:ss", Locale.ROOT);
adjustTimeZone(df);
// 2012-03-14 Ben: Ugh, what's a non-lame way of forcing it to parse to "this year"?
Date date = df.parse(dateString);
final Calendar c = df.getCalendar();
c.setTime(date);
// Add 1 to the month value because Calendar.MONTH is zero-based and
// java.time.Month values are 1-based
c.set(Calendar.YEAR, ZonedDateTimeBuilder.getBestYearForMonth(c.get(Calendar.MONTH) + 1));
return c.getTime();
}
} catch (final Exception e) {
LOG.debug("Unable to parse date '{}'", dateString, e);
return null;
}
}