本文整理了Java中java.time.Clock.system()
方法的一些代码示例,展示了Clock.system()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clock.system()
方法的具体详情如下:
包路径:java.time.Clock
类名称:Clock
方法名:system
[英]Obtains a clock that returns the current instant using best available system clock.
This clock is based on the best available system clock. This may use System#currentTimeMillis(), or a higher resolution clock if one is available.
Conversion from instant to date or time uses the specified time-zone.
The returned implementation is immutable, thread-safe and Serializable.
[中]使用最佳可用系统时钟获取返回当前时刻的时钟。
此时钟基于最佳可用系统时钟。这可能使用System#currentTimeMillis(),或更高分辨率的时钟(如果有)。
从即时到日期或时间的转换使用指定的时区。
返回的实现是不可变的、线程安全的和可序列化的。
代码示例来源:origin: neo4j/neo4j
@Override
public Clock withZone( ZoneId zone )
{
return Clock.system( zone ); // the users of this method do not need a NanoClock
}
代码示例来源:origin: apache/flume
public SyslogUtils(Integer defaultSize, Set<String> keepFields, boolean isUdp) {
this(defaultSize, keepFields, isUdp, Clock.system(Clock.systemDefaultZone().getZone()));
}
代码示例来源:origin: apache/metron
@Override
public void configure(Map<String, Object> parserConfig) {
String timeZone = (String) parserConfig.get("deviceTimeZone");
if (timeZone != null)
deviceClock = Clock.system(ZoneId.of(timeZone));
else {
deviceClock = Clock.systemUTC();
LOG.warn("[Metron] No device time zone provided; defaulting to UTC");
}
}
代码示例来源:origin: apache/metron
@Override
public void configure(Map<String, Object> parserConfig) {
// we'll pull out the clock stuff ourselves
String timeZone = (String) parserConfig.get("deviceTimeZone");
if (timeZone != null)
deviceClock = Clock.system(ZoneId.of(timeZone));
else {
deviceClock = Clock.systemUTC();
LOG.warn("[Metron] No device time zone provided; defaulting to UTC");
}
syslogParser = buildSyslogParser(parserConfig);
}
代码示例来源:origin: org.apache.flume/flume-ng-core
public SyslogUtils(Integer defaultSize, Set<String> keepFields, boolean isUdp) {
this(defaultSize, keepFields, isUdp, Clock.system(Clock.systemDefaultZone().getZone()));
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
reader.moveDown();
final ZoneId zone = (ZoneId)context.convertAnother(null, ZoneId.class);
reader.moveUp();
return Clock.system(zone);
}
}
代码示例来源:origin: speedment/speedment
public static void report(final InfoComponent info,
final ProjectComponent projects,
final Event event) {
requireNonNull(info);
requireNonNull(projects);
requireNonNull(event);
if (TestSettings.isTestMode()) {
return;
}
final Project project = projects.getProject();
final Map<String, Object> ping = new HashMap<>();
ping.put("userId", InternalEmailUtil.getUserId().toString());
ping.put("appId", project.getAppId());
ping.put("eventType", event.eventName);
ping.put("productName", info.getTitle());
ping.put("productVersion", info.getImplementationVersion());
ping.put("databases", project.dbmses()
.map(Dbms::getTypeName)
.distinct()
.collect(toList())
);
ping.put("emailAddress", InternalEmailUtil.getEmail());
ping.put("computerName", HOST_NAME.getOrCompute(Statistics::getComputerName));
ping.put("dateStarted", STARTED.getOrCompute(
() -> Instant.now(Clock.system(ZoneId.of("UTC"))).getEpochSecond()
));
sendPostRequest(PING_URL, Json.toJson(ping));
}
代码示例来源:origin: org.neo4j/neo4j-common
@Override
public Clock withZone( ZoneId zone )
{
return Clock.system( zone ); // the users of this method do not need a NanoClock
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Obtains the current date from the system clock in the specified time-zone.
* <p>
* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.
* Specifying the time-zone avoids dependence on the default time-zone.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @param zone the zone ID to use, not null
* @return the current date using the system clock, not null
*/
public static LocalDate now(ZoneId zone) {
return now(Clock.system(zone));
}
代码示例来源:origin: apache/cxf
/**
* Add a date header at the current time using the ZoneOffset. Date format is http
*/
public static void addDateHeader(Map<String, List<String>> messageHeaders, ZoneOffset zoneOffset) {
String date = DateTimeFormatter.RFC_1123_DATE_TIME
.format(LocalDateTime.now().atZone(Clock.system(zoneOffset).getZone()));
messageHeaders.put("Date", Collections.singletonList(date));
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Override
public Clock getClock() {
return Clock.system( greeter.zoneId() );
}
}
代码示例来源:origin: org.apache.cxf/cxf-rt-rs-security-http-signature
/**
* Add a date header at the current time using the ZoneOffset. Date format is http
*/
public static void addDateHeader(Map<String, List<String>> messageHeaders, ZoneOffset zoneOffset) {
String date = DateTimeFormatter.RFC_1123_DATE_TIME
.format(LocalDateTime.now().atZone(Clock.system(zoneOffset).getZone()));
messageHeaders.put("Date", Collections.singletonList(date));
}
代码示例来源:origin: com.jtransc/jtransc-rt
public static Clock tickMinutes(ZoneId zone) {
return tick(system(zone), Duration.ofMinutes(1));
}
代码示例来源:origin: org.threeten/threeten-extra
/**
* Obtains the current {@code InternationalFixedDate} from the system clock in the specified time-zone.
* <p>
* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.
* Specifying the time-zone avoids dependence on the default time-zone.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @param zone the zone ID to use, not null
* @return the current date using the system clock, not null
*/
public static InternationalFixedDate now(ZoneId zone) {
return now(Clock.system(zone));
}
代码示例来源:origin: org.threeten/threeten-extra
/**
* Obtains the current {@code EthiopicDate} from the system clock in the specified time-zone.
* <p>
* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.
* Specifying the time-zone avoids dependence on the default time-zone.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @param zone the zone ID to use, not null
* @return the current date using the system clock, not null
*/
public static EthiopicDate now(ZoneId zone) {
return now(Clock.system(zone));
}
代码示例来源:origin: org.threeten/threeten-extra
/**
* Obtains the current {@code DiscordianDate} from the system clock in the specified time-zone.
* <p>
* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.
* Specifying the time-zone avoids dependence on the default time-zone.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @param zone the zone ID to use, not null
* @return the current date using the system clock, not null
*/
public static DiscordianDate now(ZoneId zone) {
return now(Clock.system(zone));
}
代码示例来源:origin: org.threeten/threeten-extra
/**
* Obtains the current {@code CopticDate} from the system clock in the specified time-zone.
* <p>
* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.
* Specifying the time-zone avoids dependence on the default time-zone.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @param zone the zone ID to use, not null
* @return the current date using the system clock, not null
*/
public static CopticDate now(ZoneId zone) {
return now(Clock.system(zone));
}
代码示例来源:origin: x-stream/xstream
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
reader.moveDown();
final ZoneId zone = (ZoneId)context.convertAnother(null, ZoneId.class);
reader.moveUp();
return Clock.system(zone);
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.xstream-java8
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
reader.moveDown();
final ZoneId zone = (ZoneId)context.convertAnother(null, ZoneId.class);
reader.moveUp();
return Clock.system(zone);
}
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
reader.moveDown();
final ZoneId zone = (ZoneId)context.convertAnother(null, ZoneId.class);
reader.moveUp();
return Clock.system(zone);
}
}
内容来源于网络,如有侵权,请联系作者删除!