use of org.joda.time.MutableDateTime in project components by Talend.
the class XMLGregorianCalendarToDateTimeConverter method convertToDatum.
@Override
public XMLGregorianCalendar convertToDatum(Object timestamp) {
if (timestamp == null) {
return null;
}
long timestampMillis;
if (timestamp instanceof Long) {
timestampMillis = ((Long) timestamp).longValue();
} else if (timestamp instanceof Date) {
timestampMillis = ((Date) timestamp).getTime();
} else {
throw new IllegalArgumentException("Unsupported Avro timestamp value: " + timestamp);
}
MutableDateTime dateTime = new MutableDateTime();
dateTime.setMillis(timestampMillis);
XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar();
xts.setYear(dateTime.getYear());
xts.setMonth(dateTime.getMonthOfYear());
xts.setDay(dateTime.getDayOfMonth());
xts.setHour(dateTime.getHourOfDay());
xts.setMinute(dateTime.getMinuteOfHour());
xts.setSecond(dateTime.getSecondOfMinute());
xts.setMillisecond(dateTime.getMillisOfSecond());
xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000);
return xts;
}
use of org.joda.time.MutableDateTime in project pancm_project by xuwujing.
the class jodaTest method jodaTest.
/**
* 日期方法
*/
private static void jodaTest() {
// 当前时间戳
DateTime datetime = new DateTime();
// 当前的英文星期几
// Week:Wednesday
System.out.println("Week:" + datetime.dayOfWeek().getAsText(Locale.ENGLISH));
// 本地的日期格式
// LocalDate:2017-11-02
System.out.println("LocalDate:" + datetime.toLocalDate());
// 本地的当前时间 包含毫秒
// LocalDateTime:2017-11-02T08:40:04.529
System.out.println("LocalDateTime:" + datetime.toLocalDateTime());
// 格式化日期
// 时间:2017年11月2日
System.out.println("时间:" + datetime.toString(DateTimeFormat.forPattern("yyyy年M月d日")));
// 加上100小时之后是星期几(中文)
// dayOfWeek:星期一
System.out.println("dayOfWeek:" + datetime.plusHours(100).dayOfWeek().getAsText(Locale.CHINA));
// 加100天的日期
// toLocalDate():2018-02-10
System.out.println("toLocalDate():" + datetime.plusDays(100).toLocalDate());
// 十年前的今天是星期几(默认中文)
// minusYears():星期五
System.out.println("minusYears():" + datetime.minusYears(10).dayOfWeek().getAsText());
// 离双11还有多少小时
// 离双11的时间:207
System.out.println("离双11的时间:" + Hours.hoursBetween(datetime, new DateTime("2017-11-11")).getHours());
// 伦敦的时间:2017-11-02T01:24:15.139Z
// 伦敦的时间:2017-11-02T01:24:15.139Z
System.out.println("伦敦的时间:" + datetime.withZone(DateTimeZone.forID("Europe/London")));
// 标准时间
System.out.println("标准时间:" + datetime.withZone(DateTimeZone.UTC));
// 当前可变的时间
MutableDateTime mdt = new MutableDateTime();
// 10年后的时间
DateTime dt = datetime.plusYears(10);
// 2027-11-02T09:06:36.883+08:00
System.out.println("十年之后:" + dt);
while (mdt.isBefore(dt)) {
// 循环一次加一天
mdt.addDays(1);
// 是13号,并且是星期五
if (mdt.getDayOfMonth() == 13 && mdt.getDayOfWeek() == 5) {
// 打印出十年内所有的黑色星期五
System.out.println("黑色星期五:" + mdt);
/*
* 星期五:2018-04-13T09:13:40.551+08:00
星期五:2018-07-13T09:13:40.551+08:00
星期五:2019-09-13T09:13:40.551+08:00
星期五:2019-12-13T09:13:40.551+08:00
星期五:2020-03-13T09:13:40.551+08:00
星期五:2020-11-13T09:13:40.551+08:00
星期五:2021-08-13T09:13:40.551+08:00
星期五:2022-05-13T09:13:40.551+08:00
星期五:2023-01-13T09:13:40.551+08:00
星期五:2023-10-13T09:13:40.551+08:00
星期五:2024-09-13T09:13:40.551+08:00
星期五:2024-12-13T09:13:40.551+08:00
星期五:2025-06-13T09:13:40.551+08:00
星期五:2026-02-13T09:13:40.551+08:00
星期五:2026-03-13T09:13:40.551+08:00
星期五:2026-11-13T09:13:40.551+08:00
星期五:2027-08-13T09:13:40.551+08:00
*/
}
}
// 转换成jdk的Date格式
Date jdkDate = datetime.toDate();
// jdkDate:Thu Nov 02 09:51:13 CST 2017
System.out.println("jdkDate:" + jdkDate);
// jdk的Date转换成Joda的Date
datetime = new DateTime(jdkDate);
// JodaDate:2017-11-02T09:51:13.691+08:00
System.out.println("JodaDate:" + datetime);
}
use of org.joda.time.MutableDateTime in project beam by apache.
the class MutationKeyEncoder method encodeDate.
private static int encodeDate(Date date) {
MutableDateTime jodaDate = new MutableDateTime();
jodaDate.setDate(date.getYear(), date.getMonth(), date.getDayOfMonth());
return Days.daysBetween(MIN_DATE, jodaDate).getDays();
}
use of org.joda.time.MutableDateTime in project cu-kfs by CU-CommunityApps.
the class KimFeed method getTimestampForStartOfDay.
private Timestamp getTimestampForStartOfDay(DateTime dateTime) {
MutableDateTime startOfDay = new MutableDateTime(dateTime);
startOfDay.setHourOfDay(0);
startOfDay.setMinuteOfHour(0);
startOfDay.setSecondOfMinute(0);
return new Timestamp(startOfDay.getMillis());
}
Aggregations