本文整理汇总了Java中org.joda.time.Days类的典型用法代码示例。如果您正苦于以下问题:Java Days类的具体用法?Java Days怎么用?Java Days使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Days类属于org.joda.time包,在下文中一共展示了Days类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDaysBetween
import org.joda.time.Days; //导入依赖的package包/类
public static int getDaysBetween(final String date1, final String date2, String format){
try {
final DateTimeFormatter fmt =
DateTimeFormat
.forPattern(format)
.withChronology(
LenientChronology.getInstance(
GregorianChronology.getInstance()));
return Days.daysBetween(
fmt.parseDateTime(date1),
fmt.parseDateTime(date2)
).getDays();
} catch (Exception ex) {
ex.printStackTrace();
return 0;
}
}
示例2: exec
import org.joda.time.Days; //导入依赖的package包/类
@Override
public Long exec(Tuple input) throws IOException
{
if (input == null || input.size() < 2) {
return null;
}
// Set the time to default or the output is in UTC
DateTimeZone.setDefault(DateTimeZone.UTC);
DateTime startDate = new DateTime(input.get(0).toString());
DateTime endDate = new DateTime(input.get(1).toString());
// Larger date first
Days d = Days.daysBetween(endDate, startDate);
long days = d.getDays();
return days;
}
示例3: calculateRadiusOfGyrationOverTime
import org.joda.time.Days; //导入依赖的package包/类
/**
* Calculates a list of progressing radius of gyration numbers based on time
* unit given. Currently, day is supported.
*
* @param traces
* location traces of an individual
* @param unit
* spatial distance unit
* @param timeUnit
* time unit for radius of gyration calculation. Day is supported.
* @return an array of calculated radius of gyration.
* @throws TimeUnitNotSupportedException
*/
public double[] calculateRadiusOfGyrationOverTime(List<LocationTrace> traces,
SpatialDistanceUnit unit, TimeUnit timeUnit) throws TimeUnitNotSupportedException{
if (timeUnit != TimeUnit.DAYS){
throw new TimeUnitNotSupportedException(
timeUnit + " is not supported. Please pass days as time unit.");
}
LocationTraceHelper traceHelper = new LocationTraceHelper();
List<LocationTrace> selectedTraces;
LocalDateTime firstTraceTime = traces.get(0).getLocalTime().minusMinutes(1);
LocalDateTime lastTraceTime = traces.get(traces.size()-1).getLocalTime();
double[] rogResults;
LocalDateTime curentEndDate;
int numberOfDays = Days.daysBetween(firstTraceTime, lastTraceTime).getDays();
rogResults = new double[numberOfDays-1];
for(int i=1; i < numberOfDays; i++ ){
curentEndDate = firstTraceTime.plusDays(i).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
selectedTraces = traceHelper.selectBetweenDates(traces, firstTraceTime, curentEndDate);
rogResults[i-1] = calculateRadiusOfGyration(selectedTraces);
}
return rogResults;
}
示例4: updateAppUsage
import org.joda.time.Days; //导入依赖的package包/类
/**
* Updates the number of the days the app was used
*
* @param context needed to fetch defaultSharedPreferences
*/
public static void updateAppUsage(Context context) {
long currentTime = System.currentTimeMillis();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
long lastUsageTime = sharedPreferences.getLong(PREF_APP_LAST_USAGE, -1);
if (lastUsageTime == -1) {
editor.putLong(PREF_APP_LAST_USAGE, currentTime);
editor.putLong(PREF_START_OF_CONSECUTIVE_DAYS, currentTime);
} else {
//First check if it's been more than a day since last usage
int days = Days.daysBetween(new DateTime(lastUsageTime), new DateTime(currentTime)).getDays();
if (days > 1) {
editor.putLong(PREF_START_OF_CONSECUTIVE_DAYS, currentTime);
}
editor.putLong(PREF_APP_LAST_USAGE, currentTime);
}
editor.apply();
}
示例5: lengthBetween
import org.joda.time.Days; //导入依赖的package包/类
/**
* 获得两个时间点之间的时间跨度
*
* @param time1
* 开始的时间点
* @param time2
* 结束的时间点
* @param timeUnit
* 跨度的时间单位 see {@link JodaTime}
* (支持的时间单位有DAY,HOUR,MINUTE,SECOND,MILLI)
*/
public static long lengthBetween(DateTime time1, DateTime time2,
DurationFieldType timeUnit) {
Duration duration = Days.daysBetween(time1, time2).toStandardDuration();
if (timeUnit == JodaTime.DAY) {
return duration.getStandardDays();
} else if (timeUnit == JodaTime.HOUR) {
return duration.getStandardHours();
} else if (timeUnit == JodaTime.MINUTE) {
return duration.getStandardMinutes();
} else if (timeUnit == JodaTime.SECOND) {
return duration.getStandardSeconds();
} else if (timeUnit == JodaTime.MILLI) {
return duration.getMillis();
} else {
throw new RuntimeException(
"TimeUnit not supported except DAY,HOUR,MINUTE,SECOND,MILLI");
}
}
示例6: fv
import org.joda.time.Days; //导入依赖的package包/类
protected double fv() {
double spot = cache.marketPrices.getUnchecked(marketPriceKey).getLastPrice();
double sigma = cache.vols.getUnchecked(volKey).getValue();
double riskFreeRate = cache.intRates.getUnchecked(interestRateKey).getValue();
double strike = instrument.getStrike();
//TODO Enhancement, allow use the asOf time from ValuationRequest for asofPricing
LocalDate now = LocalDate.now();
double time = ((double) Days.daysBetween(now, LocalDate.parse(Integer.toString(instrument.getExpDate()), FORMAT)).getDays()) / DAY_IN_YEAR;
if (instrument.getOptionType() == Instrument.OptionType.P) {
return putPrice(spot, strike, riskFreeRate, sigma, time);
} else {
return callPrice(spot, strike, riskFreeRate, sigma, time);
}
}
示例7: intervalTest
import org.joda.time.Days; //导入依赖的package包/类
@Test
public void intervalTest() {
// 获取当前日期到本月最后一天还剩多少天
LocalDate now = LocalDate.now();
LocalDate lastDayOfMonth = LocalDate.now().dayOfMonth().withMaximumValue();
System.out.println(Days.daysBetween(now, lastDayOfMonth).getDays());
System.out.println(DateTime.now().toString(DEFAULT_DATE_FORMATTER));
System.out.println(DateTime.now().dayOfMonth().withMaximumValue().toString(DEFAULT_DATE_FORMATTER));
Interval interval = new Interval(DateTime.now(), DateTime.now().dayOfMonth().withMaximumValue());
Period p = interval.toPeriod();
System.out.println(interval.toDuration().getStandardDays());
System.out.format("时间相差:%s 年, %s 月, %s 天, %s 时, %s 分, %s 秒",
p.getYears(), p.getMonths(), p.getDays(), p.getHours(), p.getMinutes(), p.getSeconds());
}
示例8: Habit
import org.joda.time.Days; //导入依赖的package包/类
public Habit(String name, int timesCompleted, String creationDate) {
this.name = name;
this.timesCompleted = timesCompleted;
this.creationDate = creationDate;
double tryingToGetTimesPerDay = 0;
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
try {
java.util.Date creationTime = format.parse(creationDate);
Calendar calendar = Calendar.getInstance();
calendar.setTime(creationTime);
int daysSinceCreation = Math.max(1, Days.daysBetween(new DateTime(creationTime), DateTime.now()).getDays());
tryingToGetTimesPerDay = ((float) timesCompleted) / daysSinceCreation;
} catch (ParseException e) {
Timber.e(e, "WTF parse ");
}
timesPerDay = tryingToGetTimesPerDay;
}
示例9: build
import org.joda.time.Days; //导入依赖的package包/类
void build() {
while (cursor != null && cursor.moveToNext()) {
int allDay = cursor.getInt(4);
long beginTime, endTime;
if (allDay == 1) {
beginTime = new DateTime(cursor.getLong(2), DateTimeZone.forID(cursor.getString(6))).withZone(DateTimeZone.getDefault()).withTimeAtStartOfDay().getMillis();
//to prevent multiple alarms at midnight. Even if current event says alarm at midnight, we anyway have loader alarm
endTime = Long.MAX_VALUE;
} else {
beginTime = new DateTime(cursor.getLong(2), DateTimeZone.forID(cursor.getString(6))).withZone(DateTimeZone.getDefault()).getMillis();
endTime = new DateTime(cursor.getLong(3), DateTimeZone.forID(cursor.getString(6))).withZone(DateTimeZone.getDefault()).getMillis();
}
int dayDiff = Days.daysBetween(new DateTime().withTimeAtStartOfDay().toLocalDate(), new DateTime(beginTime).toLocalDate()).getDays();
if (dayDiff >= 0) {
events[Enums.EventInfo.Title.ordinal()].add(getFormattedTitle(cursor.getString(0), cursor.getString(1)));
events[Enums.EventInfo.Time.ordinal()].add(getFormattedTime(beginTime, endTime, allDay, dayDiff));
events[Enums.EventInfo.Color.ordinal()].add(cursor.getString(5));
times[Enums.TimesInfo.Begin.ordinal()].add(beginTime);
times[Enums.TimesInfo.End.ordinal()].add(endTime);
}
}
if (cursor != null) {
cursor.close();
}
}
示例10: get_interval
import org.joda.time.Days; //导入依赖的package包/类
private String get_interval(DateTime largerDatetime, DateTime smallerDateTime) throws HydraClientException{
int year_diff = Years.yearsBetween(smallerDateTime, largerDatetime).getYears();
int month_diff = Months.monthsBetween(smallerDateTime, largerDatetime).getMonths();
int day_diff = Days.daysBetween(smallerDateTime, largerDatetime).getDays();
int hour_diff = Hours.hoursBetween(smallerDateTime, largerDatetime).getHours();
int min_diff = Minutes.minutesBetween(smallerDateTime, largerDatetime).getMinutes();
if (year_diff > 0){return year_diff+"YEAR";}
if (month_diff > 0){return month_diff+"MONTH";}
if (day_diff > 0){return day_diff+"DAY";}
if (hour_diff > 0){return hour_diff+"HOUR";}
if (min_diff > 0){return min_diff+"MIN";}
throw new HydraClientException("Could not compute interval between times " + smallerDateTime.toString() + "and" + largerDatetime.toString());
}
示例11: DAYS
import org.joda.time.Days; //导入依赖的package包/类
/**
* Returns the number of days between two dates.
*/
@Function("DAYS")
@FunctionParameters({
@FunctionParameter("startDate"),
@FunctionParameter("endDate")})
public Integer DAYS(Object startDate, Object endDate){
Date startDateObj = convertDateObject(startDate);
if(startDateObj==null) {
logCannotConvertToDate();
return null;
}
Date endDateObj = convertDateObject(endDate);
if(endDateObj==null){
logCannotConvertToDate();
return null;
}
else{
LocalDate dt1=new LocalDate(startDateObj);
LocalDate dt2=new LocalDate(endDateObj);
return Days.daysBetween(dt1, dt2).getDays();
}
}
示例12: onLoadFinished
import org.joda.time.Days; //导入依赖的package包/类
@Override
public void onLoadFinished(Loader<CheckLastVO> loader, CheckLastVO data) {
if (data != null){
DateTime date = new DateTime(data.getVerificationDate());
DateTime today = new DateTime();
int days = Days.daysBetween(date, today).getDays();
lastVerificationTime.setVisibility(View.VISIBLE);
lastVerificationTime.setText(getString(R.string.x_period, days));
verification.setText(getString(R.string.last_checking));
} else {
verification.setText(getString(R.string.first_check));
}
}
示例13: getCorrectRepeatingDates
import org.joda.time.Days; //导入依赖的package包/类
private ArrayList<DateTime> getCorrectRepeatingDates(RepeatingPayment payment, DateTime now)
{
ArrayList<DateTime> dates = new ArrayList<>();
DateTime startDate = DateTime.parse(payment.getDate());
//repeat every x days
if(payment.getRepeatInterval() != 0)
{
int numberOfDays = Days.daysBetween(startDate, now).getDays();
int occurrences = numberOfDays / payment.getRepeatInterval();
for(int i = 0; i <= occurrences; i++)
{
dates.add(startDate.plusDays(i * payment.getRepeatInterval()));
}
}
//repeat every month on day x
else
{
int numberOfMonths = Months.monthsBetween(startDate.withDayOfMonth(payment.getRepeatMonthDay()), now).getMonths();
for(int i = 0; i <= numberOfMonths; i++)
{
dates.add(startDate.plusMonths(i));
}
}
return dates;
}
示例14: fromIso
import org.joda.time.Days; //导入依赖的package包/类
@Override
public DateTimeUnit fromIso( DateTimeUnit dateTimeUnit )
{
if ( dateTimeUnit.getYear() >= START_PERSIAN.getYear() &&
dateTimeUnit.getYear() <= STOP_PERSIAN.getYear() )
{
return new DateTimeUnit( dateTimeUnit.getYear(), dateTimeUnit.getMonth(), dateTimeUnit.getDay(),
dateTimeUnit.getDayOfWeek(), false );
}
if ( dateTimeUnit.getYear() < START_ISO.getYear() || dateTimeUnit.getYear() > STOP_ISO.getYear() )
{
throw new InvalidCalendarParametersException(
"Illegal ISO year, must be between " + START_ISO.getYear() + " and " + STOP_ISO.getYear() +
", was given " + dateTimeUnit.getYear() );
}
DateTime start = START_ISO.toJodaDateTime();
DateTime end = dateTimeUnit.toJodaDateTime();
return plusDays( START_PERSIAN, Days.daysBetween( start, end ).getDays() );
}
示例15: Reminder
import org.joda.time.Days; //导入依赖的package包/类
/**
* Create default auto message for date of anniversary
*/
public Reminder(Date dateEvent, int minuteBeforeEvent) {
this.id = ID_UNDEFINED;
this.dateEvent = dateEvent;
this.dateEvent = new DateTime(this.dateEvent)
.withHourOfDay(0)
.withMinuteOfHour(0)
.withSecondOfMinute(0)
.withMillisOfSecond(0)
.toDate();
DateTime dateReminder = new DateTime(dateEvent).minusMinutes(minuteBeforeEvent);
this.hourOfDay = dateReminder.getHourOfDay();
this.minuteOfHour = dateReminder.getMinuteOfHour();
this.daysBefore = Days.daysBetween(dateReminder, new DateTime(dateEvent)).getDays();
if(minuteBeforeEvent > 0)
this.daysBefore++;
}