Java Code Examples for org.joda.time.LocalDate#toDate()

The following examples show how to use org.joda.time.LocalDate#toDate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateUtils.java    From Almost-Famous with MIT License 5 votes vote down vote up
/**
 * 根据周数,获取开始日期、结束日期
 *
 * @param week 周期  0本周,-1上周,-2上上周,1下周,2下下周
 * @return 返回date[0]开始日期、date[1]结束日期
 */
public static Date[] getWeekStartAndEnd(int week) {
    DateTime dateTime = new DateTime();
    LocalDate date = new LocalDate(dateTime.plusWeeks(week));

    date = date.dayOfWeek().withMinimumValue();
    Date beginDate = date.toDate();
    Date endDate = date.plusDays(6).toDate();
    return new Date[]{beginDate, endDate};
}
 
Example 2
Source File: DateUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static Date toDate(String dateString) {

        if (StringUtils.isEmpty(dateString)) {
            throw new IllegalArgumentException("date string cannot be empty");
        }

        DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd");
        LocalDate dateTime = dtf.parseLocalDate(dateString);

        return dateTime.toDate();
    }
 
Example 3
Source File: DateUtils.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
/**
 * 根据周数,获取开始日期、结束日期
 * @param week  周期  0本周,-1上周,-2上上周,1下周,2下下周
 * @return  返回date[0]开始日期、date[1]结束日期
 */
public static Date[] getWeekStartAndEnd(int week) {
    DateTime dateTime = new DateTime();
    LocalDate date = new LocalDate(dateTime.plusWeeks(week));

    date = date.dayOfWeek().withMinimumValue();
    Date beginDate = date.toDate();
    Date endDate = date.plusDays(6).toDate();
    return new Date[]{beginDate, endDate};
}
 
Example 4
Source File: DateUtils.java    From boot-actuator with MIT License 5 votes vote down vote up
/**
 * 根据周数,获取开始日期、结束日期
 * @param week  周期  0本周,-1上周,-2上上周,1下周,2下下周
 * @return  返回date[0]开始日期、date[1]结束日期
 */
public static Date[] getWeekStartAndEnd(int week) {
    DateTime dateTime = new DateTime();
    LocalDate date = new LocalDate(dateTime.plusWeeks(week));

    date = date.dayOfWeek().withMinimumValue();
    Date beginDate = date.toDate();
    Date endDate = date.plusDays(6).toDate();
    return new Date[]{beginDate, endDate};
}
 
Example 5
Source File: SelfServiceDataSetCRUD.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean isADate(JSONObject jsonConf, IDataStore dataStore, int columnIndex) throws JSONException {
	String dateFormat = jsonConf.get(DataSetConstants.FILE_DATE_FORMAT).toString();
	for (int i = 0; i < Math.min(10, dataStore.getRecordsCount()); i++) {
		IRecord record = dataStore.getRecordAt(i);
		IField field = record.getFieldAt(columnIndex);
		Object value = field.getValue();
		if (value instanceof Date) {
			if (value instanceof Timestamp)
				return false;

			// it's already a Date, skip the check
			continue;
		}
		try {
			// JDK 8 version
			/*
			 * DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat); LocalDate localDate = LocalDate.parse((String) field.getValue(),
			 * formatter); Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
			 */
			DateTimeFormatter formatter = DateTimeFormat.forPattern(dateFormat);
			LocalDate localDate = LocalDate.parse((String) field.getValue(), formatter);
			localDate.toDate();

		} catch (Exception ex) {
			logger.debug(field.getValue() + " is not a date");
			return false;
		}
	}
	return true;
}
 
Example 6
Source File: DateUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static Date toDate(Object dateString) {

        if (dateString == null) {
            throw new IllegalArgumentException("date string cannot be empty");
        }

        DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd");
        LocalDate dateTime = dtf.parseLocalDate((String) dateString);

        return dateTime.toDate();
    }
 
Example 7
Source File: DateWidget.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Override
public IAnswerData getAnswer() {
    mDatePicker.clearFocus();

    LocalDate ldt = new LocalDate(mDatePicker.getYear(), mDatePicker.getMonth() + 1,
            mDatePicker.getDayOfMonth());
    return new DateData(ldt.toDate());
}
 
Example 8
Source File: LocalDateConverter.java    From blog-spring with MIT License 4 votes vote down vote up
@Override
public Date convertToDatabaseColumn(LocalDate attribute) {
  return attribute == null ? null : attribute.toDate();
}
 
Example 9
Source File: JodaLocalDateTojuDateConverter.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
@Override
public Date convert(LocalDate in, Context context) throws Exception {
    if (in == null) return null;
    return in.toDate();
}
 
Example 10
Source File: DateUtil.java    From activiti6-boot2 with Apache License 2.0 3 votes vote down vote up
public static Date addDate(Date startDate, Integer years, Integer months, Integer days) {

        LocalDate currentDate = new LocalDate(startDate);

        currentDate = currentDate.plusYears(years);
        currentDate = currentDate.plusMonths(months);
        currentDate = currentDate.plusDays(days);

        return currentDate.toDate();
    }
 
Example 11
Source File: DateUtil.java    From activiti6-boot2 with Apache License 2.0 3 votes vote down vote up
public static Date subtractDate(Date startDate, Integer years, Integer months, Integer days) {

        LocalDate currentDate = new LocalDate(startDate);

        currentDate = currentDate.minusYears(years);
        currentDate = currentDate.minusMonths(months);
        currentDate = currentDate.minusDays(days);

        return currentDate.toDate();
    }
 
Example 12
Source File: DateUtil.java    From flowable-engine with Apache License 2.0 3 votes vote down vote up
public static Date addDate(Object startDate, Object years, Object months, Object days) {

        LocalDate currentDate = new LocalDate(startDate);
        
        currentDate = currentDate.plusYears(intValue(years));
        currentDate = currentDate.plusMonths(intValue(months));
        currentDate = currentDate.plusDays(intValue(days));

        return currentDate.toDate();
    }
 
Example 13
Source File: DateUtil.java    From flowable-engine with Apache License 2.0 3 votes vote down vote up
public static Date subtractDate(Object startDate, Object years, Object months, Object days) {

        LocalDate currentDate = new LocalDate(startDate);

        currentDate = currentDate.minusYears(intValue(years));
        currentDate = currentDate.minusMonths(intValue(months));
        currentDate = currentDate.minusDays(intValue(days));

        return currentDate.toDate();
    }