本文整理汇总了Java中org.joda.time.DateTime.minusYears方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.minusYears方法的具体用法?Java DateTime.minusYears怎么用?Java DateTime.minusYears使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.DateTime
的用法示例。
在下文中一共展示了DateTime.minusYears方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseRfc3164Time
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* Parse the RFC3164 date format. This is trickier than it sounds because this
* format does not specify a year so we get weird edge cases at year
* boundaries. This implementation tries to "do what I mean".
* @param ts RFC3164-compatible timestamp to be parsed
* @return Typical (for Java) milliseconds since the UNIX epoch
*/
protected long parseRfc3164Time(String ts) {
DateTime now = DateTime.now();
int year = now.getYear();
ts = TWO_SPACES.matcher(ts).replaceFirst(" ");
DateTime date;
try {
date = rfc3164Format.parseDateTime(ts);
} catch (IllegalArgumentException e) {
logger.debug("rfc3164 date parse failed on (" + ts + "): invalid format", e);
return 0;
}
// rfc3164 dates are really dumb.
/*
* Some code to try and add some smarts to the year insertion as without a year in the message
* we need to make some educated guessing.
* First set the "fixed" to be the timestamp with the current year.
* If the "fixed" time is more than one month in the future then roll it back a year.
* If the "fixed" time is more than eleven months in the past then roll it forward a year.
* This gives us a 12 month rolling window (11 months in the past, 1 month in the future) of
* timestamps.
*/
if (date != null) {
DateTime fixed = date.withYear(year);
// flume clock is ahead or there is some latency, and the year rolled
if (fixed.isAfter(now) && fixed.minusMonths(1).isAfter(now)) {
fixed = date.minusYears(1);
// flume clock is behind and the year rolled
} else if (fixed.isBefore(now) && fixed.plusMonths(1).isBefore(now)) {
fixed = date.plusYears(1);
}
date = fixed;
}
if (date == null) {
return 0;
}
return date.getMillis();
}