本文整理汇总了Java中java.util.concurrent.TimeUnit.toSeconds方法的典型用法代码示例。如果您正苦于以下问题:Java TimeUnit.toSeconds方法的具体用法?Java TimeUnit.toSeconds怎么用?Java TimeUnit.toSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.TimeUnit
的用法示例。
在下文中一共展示了TimeUnit.toSeconds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listFeaturesSinceInner
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
private FeatureCollection listFeaturesSinceInner(String nsKey, long timestamp,
TimeUnit timeUnit) {
try {
long ts = timeUnit.toSeconds(timestamp);
String url = UriBuilder.builder(baseUri)
.path(PATH_FEATURES)
.path(nsKey)
.query(PARAM_SINCE, ts + "")
.buildString();
return toFeatureCollection(getRequest(nsKey, url).body().string());
} catch (IOException e) {
throw new FeatureException(Problem.localProblem(e.getMessage(), ""), e);
}
}
示例2: ttl
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@Override
public void ttl(int lifetime, TimeUnit unit) {
int seconds = (int) unit.toSeconds(lifetime);
TTLValue ttlValue = new TTLValue(seconds);
HttpResponse httpResponse = httpclient.post(HttpAPI.TTL, ttlValue.toJSON());
ResultResponse resultResponse = ResultResponse.simplify(httpResponse, this.httpCompress);
HttpStatus httpStatus = resultResponse.getHttpStatus();
switch (httpStatus) {
case ServerSuccess:
return;
case ServerNotSupport:
throw new HttpServerNotSupportException(resultResponse);
case ServerError:
throw new HttpServerErrorException(resultResponse);
default:
throw new HttpUnknowStatusException(resultResponse);
}
}
示例3: formatTimeInterval
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
private static String formatTimeInterval(long time, String format){
TimeUnit c = TimeUnit.MILLISECONDS;
long S = c.toSeconds(time);
long M = c.toMinutes(time);
long H = c.toHours(time);
long D = c.toDays(time);
long s = c.toSeconds(time - TimeUnit.MINUTES.toMillis(M));
long m = c.toMinutes(time - TimeUnit.HOURS.toMillis(H));
long h = c.toHours(time - TimeUnit.DAYS.toMillis(D));
String r = format;
r = r.replace("%S", "" + S);
r = r.replace("%M", "" + M);
r = r.replace("%H", "" + H);
r = r.replace("%D", "" + D);
r = r.replace("%s", (s > 9 ? "" : "0") + s);
r = r.replace("%m", (m > 9 ? "" : "0") + m);
r = r.replace("%h", (h > 9 ? "" : "0") + h);
return r;
}
示例4: printEventMetric
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/**
* Prints an Event Metric.
*
* @param operationStr the string with the intent operation to print
* @param eventMetric the Event Metric to print
*/
private void printEventMetric(String operationStr,
EventMetric eventMetric) {
Gauge<Long> gauge = eventMetric.lastEventTimestampGauge();
Meter meter = eventMetric.eventRateMeter();
TimeUnit rateUnit = TimeUnit.SECONDS;
double rateFactor = rateUnit.toSeconds(1);
// Print the Gauge
print(FORMAT_GAUGE, operationStr, gauge.getValue());
// Print the Meter
print(FORMAT_METER, operationStr, meter.getCount(),
meter.getMeanRate() * rateFactor,
meter.getOneMinuteRate() * rateFactor,
meter.getFiveMinuteRate() * rateFactor,
meter.getFifteenMinuteRate() * rateFactor);
}
示例5: formatTimeInterval
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/**
* Convert from an amount of time to a string in the format xxd:hh:mm:ss
* @param amount interval that needs to be formatted
* @param timeUnit the unit of the interval
* @return a formatted string representing the input interval
*/
public static String formatTimeInterval(long amount, TimeUnit timeUnit) {
long totSeconds = timeUnit.toSeconds(amount);
long seconds = totSeconds % 60;
long totMinutes = timeUnit.toMinutes(amount);
long minutes = totMinutes % 60;
long totHours = timeUnit.toHours(amount);
long hours = totHours % 24;
long days = timeUnit.toDays(amount);
String result = String.format("%02d:%02d", minutes, seconds);
if (hours+days>0) {
result = String.format("%02d:", hours) + result;
if (days>0) {
result = String.format("%dd:", days) + result;
}
}
return result;
}
示例6: JmxMeter
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
private JmxMeter(Metered metric, ObjectName objectName, TimeUnit rateUnit)
{
super(objectName);
this.metric = metric;
this.rateFactor = rateUnit.toSeconds(1);
this.rateUnit = "events/" + calculateRateUnit(rateUnit);
}
示例7: toSeconds
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
protected long toSeconds(long timeout, TimeUnit unit) {
long seconds = unit.toSeconds(timeout);
if (timeout != 0 && seconds == 0) {
seconds = 1;
}
return seconds;
}
示例8: DropwizardTransformer
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public DropwizardTransformer(final Map<String, String> baseTags,
final DropwizardMeasurementParser parser,
final boolean groupCounters,
final boolean groupGauges,
final TimeUnit rateUnit,
final TimeUnit durationUnit) {
this.baseTags = baseTags;
this.parser = parser;
this.groupCounters = groupCounters;
this.groupGauges = groupGauges;
this.rateFactor = rateUnit.toSeconds(1);
this.durationFactor = durationUnit.toNanos(1);
}
示例9: durationToTimeString
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public static String durationToTimeString(long duration) {
TimeUnit scale = TimeUnit.MILLISECONDS;
long days = scale.toDays(duration);
duration -= TimeUnit.DAYS.toMillis(days);
long hours = scale.toHours(duration);
duration -= TimeUnit.HOURS.toMillis(hours);
long minutes = scale.toMinutes(duration);
duration -= TimeUnit.MINUTES.toMillis(minutes);
long seconds = scale.toSeconds(duration);
return String.format("%d days, %d hours, %d minutes, %d seconds", days, hours, minutes, seconds);
}
示例10: TimerSerializer
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
private TimerSerializer(TimeUnit rateUnit, TimeUnit durationUnit, String timestampFieldname) {
super(JsonTimer.class);
this.timestampFieldname = timestampFieldname;
this.rateUnit = calculateRateUnit(rateUnit, "calls");
this.rateFactor = rateUnit.toSeconds(1);
this.durationUnit = durationUnit.toString().toLowerCase(Locale.US);
this.durationFactor = 1.0 / durationUnit.toNanos(1);
}
示例11: toTicks
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public static long toTicks(TimeUnit unit, long duration) {
return unit.toSeconds(duration) * 20;
}
示例12: getCacheTime
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public Long getCacheTime(String url){
if (mUrlMap!=null){
Long type = mUrlMap.get(url);
if (type!=null){
return type;
}
}
for (Map serviceMethodCache:mVector) {
for (Object entry:serviceMethodCache.keySet()){
Object o = serviceMethodCache.get(entry);
try {
if (mUrlAragsMap.containsKey(url)){
Object[] args = (Object[]) mUrlAragsMap.get(url);
String reqUrl = buildRequestUrl(o,args);
if (reqUrl.equals(url)){
Method m = (Method) entry;
Cache cache = m.getAnnotation(Cache.class);
if (cache!=null){
TimeUnit timeUnit = mDefaultTimeUnit;
if (cache.timeUnit() != TimeUnit.NANOSECONDS){
timeUnit = cache.timeUnit();
}
long t = mDefaultTime;
if (cache.time() != -1){
t = cache.time();
}
long tm = timeUnit.toSeconds(t);
getUrlMap().put(url, tm);
return tm;
}else{
getUrlMap().put(url, 0L);
return 0L;
}
}
}
} catch (Exception e) {
LogUtil.l(e);
}
}
}
getUrlMap().put(url, 0L);
return 0L;
}
示例13: FollowersOnlyEvent
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public FollowersOnlyEvent(Channel channel, long time, TimeUnit timeUnit) {
super(channel, time > -1);
this.time = timeUnit.toSeconds(time);
}
示例14: toTicks
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
private long toTicks(long amount, TimeUnit timeUnit) {
return timeUnit.toSeconds(amount) / 20;
}
示例15: realtime
import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public Builder realtime(long time, TimeUnit unit) {
this.realTimeSeconds = (int) unit.toSeconds(time);
return this;
}