本文整理汇总了Java中org.joda.time.DateTime.toDate方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.toDate方法的具体用法?Java DateTime.toDate怎么用?Java DateTime.toDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.DateTime
的用法示例。
在下文中一共展示了DateTime.toDate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public Date deserialize(JsonParser gen, DeserializationContext ctxt) throws IOException, JsonProcessingException {
String date = gen.getText();
if (StringUtils.isEmpty(date)) {
return null;
}
if (StringUtils.isNumeric(date)) {
return new Date(Long.valueOf(date));
}
try {
DateTime dt = fmt.parseDateTime(date);
return dt.toDate();
} catch (Exception e) {
throw new IOException(e);
}
}
示例2: main
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static void main(String[] args) {
DateTime startTime = new DateTime(new Date());
Long startTimeLong = startTime.minusDays(1).withTime(0, 0, 0, 0).toDate().getTime();
Long endTimeLong = new DateTime(startTime).withTime(0, 0, 0, 0).toDate().getTime();
System.out.println("startTime:"+startTime);
DateTime startTime2 = new DateTime(new Date());
startTime2 = startTime2.minusDays(0).withTime(0, 0, 0, 0);
DateTime endTime2 = new DateTime(startTime).minusDays(0).withTime(23, 59, 59, 999);
Date start = startTime2.toDate();
Date end = endTime2.toDate();
System.out.println("start:"+start);
if (start.getTime() >= startTimeLong && end.getTime() < endTimeLong) {
System.out.println("ok");
}
if (start.getTime() >= endTimeLong) {
System.out.println("not ok");
}
Date old = new Date();
Date plus1 = new DateTime(old).plusSeconds(1).toDate();
System.out.println(1000.0 / (plus1.getTime() - old.getTime()));
}
示例3: getFirstDayOfWeek
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 获取某一天所在周的周一
*
* @param date
* @return
*/
public static Date getFirstDayOfWeek(Date date) {
DateTime dateTime = new DateTime(date.getTime());
int dayOfWeek = dateTime.getDayOfWeek();
DateTime firstDate = dateTime.minusDays(dayOfWeek - 1);
firstDate = firstDate.withTime(0, 0, 0, 0);
return firstDate.toDate();
}
示例4: getFirstDayOfYear
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 获取某一天所在年的第一天
*
* @param date
* @return
*/
public static Date getFirstDayOfYear(Date date) {
DateTime dateTime = new DateTime(date.getTime());
int dayOfYear = dateTime.getDayOfYear();
DateTime firstDate = dateTime.minusDays(dayOfYear - 1);
firstDate = firstDate.withTime(0, 0, 0, 0);
return firstDate.toDate();
}
示例5: getLastOfDay
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 获取某一天最后时间
*
* @param date
* @return
*/
public static Date getLastOfDay(Date date) {
DateTime dateTime = new DateTime(date.getTime());
dateTime = dateTime.withTime(23, 59, 59, 0);
return dateTime.toDate();
}
示例6: parse
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 按照指定格式匹配解析字符串为日期
*
* @param dateStr
* @param pattern
* @return
*/
public static Date parse(@NotNull String dateStr, @NotNull String pattern) {
Objects.requireNonNull(dateStr, "data string must not null");
Objects.requireNonNull(pattern, "date pattern must not null");
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(pattern);
DateTime dateTime = dateTimeFormatter.parseDateTime(dateStr);
return dateTime.toDate();
}
示例7: getLastDayOfWeek
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 获取某一天所在周的周日
*
* @param date
* @return
*/
public static Date getLastDayOfWeek(Date date) {
DateTime dateTime = new DateTime(date.getTime());
int dayOfWeek = dateTime.getDayOfWeek();
DateTime theDateTime = new DateTime(date.getTime());
theDateTime = theDateTime.plusDays(7 - dayOfWeek);
return theDateTime.toDate();
}
示例8: testGetPublishIdToSnapshotFrom
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Test
public void testGetPublishIdToSnapshotFrom() throws Exception {
String excludeInstanceId = "exclude-352768";
List<String> instanceIds = new ArrayList<>();
instanceIds.add(excludeInstanceId);
instanceIds.add(instanceId);
instanceIds.add("extra-89351");
Date dt = new Date();
DateTime originalDateTime = new DateTime(dt);
Date originalDate = originalDateTime.toDate();
DateTime originalPlusOneDateTime = originalDateTime.plusDays(1);
Date originalPlusOneDate = originalPlusOneDateTime.toDate();
when(awsHelperService.getInstanceIdsForAutoScalingGroup(
envValues.getAutoScaleGroupNameForPublish())).thenReturn(instanceIds);
Map<String, String> instanceTags1 = new HashMap<>();
instanceTags1.put(InstanceTags.SNAPSHOT_ID.getTagName(), "");
when(awsHelperService.getTags(anyString())).thenReturn(instanceTags1);
when(awsHelperService.getLaunchTime(instanceId)).thenReturn(originalDate);
when(awsHelperService.getLaunchTime("extra-89351")).thenReturn(originalPlusOneDate);
when(httpUtil.isHttpGetResponseOk(anyString())).thenReturn(true);
String resultInstanceId = aemHelperService.getPublishIdToSnapshotFrom(excludeInstanceId);
assertThat(resultInstanceId, equalTo(instanceId));
}
示例9: strToDate
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static Date strToDate(String dateTimeStr, String formatStr) {
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(formatStr);
DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr);
return dateTime.toDate();
}
示例10: safeDate
import org.joda.time.DateTime; //导入方法依赖的package包/类
private Date safeDate(DateTime dateTime) {
return dateTime == null ? null : dateTime.toDate();
}
示例11: convert
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public Date convert(DateTime source) {
return source.toDate();
}
示例12: setLastModifiedDate
import org.joda.time.DateTime; //导入方法依赖的package包/类
public void setLastModifiedDate(final DateTime lastModifiedDate) {
this.lastModifiedDate = null == lastModifiedDate ? null : lastModifiedDate.toDate();
}
示例13: strToDate
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static Date strToDate(String dateTimeStr,String formatStr){
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(formatStr);
DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr);
return dateTime.toDate();
}
示例14: date
import org.joda.time.DateTime; //导入方法依赖的package包/类
private Date date(DateTime dateTime) {
return dateTime.toDate();
}
示例15: getDayOfWeek
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 获取指定日期当周的任意一天
*
*
* @param date 指定日期为标准
* @param week 偏移周数,正数:往后指定周数量,负数:往前指定周数量
* @param dayOfWeek 指定天数 1第一天周一 7最后一天为周日
* @return
*/
public static Date getDayOfWeek(@NotNull Date date, int week, int dayOfWeek) {
Objects.requireNonNull(date, "date must not null");
DateTime dateTime = new DateTime(date);
dateTime = dateTime.plusWeeks(week).withDayOfWeek(dayOfWeek);
return dateTime.toDate();
}