Java Code Examples for org.joda.time.DateTime#toDate()
The following examples show how to use
org.joda.time.DateTime#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: SettableDataSetterFactoryTest.java From SimpleFlatMapper with MIT License | 6 votes |
@Test public void testJodaLT() throws Exception { PropertyMapping<?, ?, DatastaxColumnKey> pm = newPM(org.joda.time.LocalTime.class, DataType.time()); Setter<SettableByIndexData, org.joda.time.LocalTime> setter = factory.getSetter(pm); org.joda.time.LocalTime ldt = org.joda.time.LocalTime.fromMillisOfDay(3600000); setter.set(statement, ldt); setter.set(statement, null); verify(statement).setTime(0, TimeUnit.SECONDS.toNanos(3600)); verify(statement).setToNull(0); final Date date = ldt.toDateTimeToday().toDate(); DateTimeZone tz2 = getNonDefaultDateTimeZone(date); DateTime dateTime = ldt.toDateTimeToday(tz2); final Date dateTz = dateTime.toDate(); Setter<SettableByIndexData, org.joda.time.LocalTime> setterTZ = factory.getSetter(newPM(org.joda.time.LocalTime.class, DataType.timestamp(), new JodaDateTimeZoneProperty(tz2))); setterTZ.set(statement, ldt); verify(statement).setTimestamp(1, new Date(dateTz.getTime())); }
Example 2
Source File: DateUtil.java From canal with Apache License 2.0 | 6 votes |
/** * 通用日期时间字符解析 * * @param datetimeStr 日期时间字符串 * @return Date */ public static Date parseDate(String datetimeStr) { if (StringUtils.isEmpty(datetimeStr)) { return null; } datetimeStr = datetimeStr.trim().replace('/', '-'); if (datetimeStr.contains("-")) { if (datetimeStr.contains(":")) { datetimeStr = datetimeStr.replace(" ", "T"); } } else if (datetimeStr.contains(":")) { datetimeStr = "T" + datetimeStr; } else { if (datetimeStr.length() == 8) { String year = datetimeStr.substring(0, 4); String month = datetimeStr.substring(4, 6); String day = datetimeStr.substring(6, 8); datetimeStr = year + "-" + month + "-" + day; } } DateTime dateTime = new DateTime(datetimeStr, dateTimeZone); return dateTime.toDate(); }
Example 3
Source File: MessageFormatting.java From levelup-java-examples with Apache License 2.0 | 6 votes |
@Test public void messageformatter_with_choice() { String pattern = "Your statement on {0, date, MM/dd/yyyy} " + "{1,choice,0#is not available|1#is {1, number, currency}}"; MessageFormat statementFormat = new MessageFormat(pattern); DateTime statementDate1 = new DateTime(2013, 5, 15, 0, 0, 0, 0); Object[] statement1 = {statementDate1.toDate(), 23444}; assertEquals("Your statement on 05/15/2013 is $23,444.00", statementFormat.format(statement1)); DateTime statementDate2 = new DateTime(2013, 6, 15, 0, 0, 0, 0); Object[] statement2 = {statementDate2.toDate(), 0}; assertEquals("Your statement on 06/15/2013 is not available", statementFormat.format(statement2)); }
Example 4
Source File: CurrentQuarterGuavaTest.java From levelup-java-examples with Apache License 2.0 | 5 votes |
@Test public void current_quarter () { DateTime firstQuarterCheck = new DateTime(2013, 1, 15, 0, 0, 0, 0); CurrentQuarterGuava currentQuarterWithGuava = new CurrentQuarterGuava(firstQuarterCheck.toDate()); assertEquals(new Integer(1), currentQuarterWithGuava.getQuarter()); }
Example 5
Source File: DateTimeRyaTypeResolver.java From rya with Apache License 2.0 | 5 votes |
@Override protected String serializeData(String data) throws RyaTypeResolverException { try { DateTime dateTime = DateTime.parse(data, XMLDATETIME_PARSER); Date value = dateTime.toDate(); return DATE_STRING_TYPE_ENCODER.encode(value); } catch (TypeEncodingException e) { throw new RyaTypeResolverException( "Exception occurred serializing data[" + data + "]", e); } }
Example 6
Source File: TaskVersionUtils.java From liteflow with Apache License 2.0 | 5 votes |
/** * 通过任务版本获取对应的时间 * @param version * @param timeUnit * @return */ public static Date getDateByVersion(String version, TimeUnit timeUnit){ String versionExpression = timeUnit.getVersionExpression(); DateTimeFormatter format = DateTimeFormat.forPattern(versionExpression); DateTime dateTime = DateTime.parse(version, format); return dateTime.toDate(); }
Example 7
Source File: DhisConvenienceTest.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates a date. * * @param day the day of the year. * @return a date. */ public Date getDay( int day ) { DateTime dataTime = DateTime.now(); dataTime = dataTime.withTimeAtStartOfDay(); dataTime = dataTime.withDayOfYear( day ); return dataTime.toDate(); }
Example 8
Source File: HourTimeCalculator.java From liteflow with Apache License 2.0 | 5 votes |
@Override public Date getStartTime() { DateTime dateTime = new DateTime(time); dateTime = dateTime.withMinuteOfHour(CommonConstants.ZERO); dateTime = dateTime.withSecondOfMinute(CommonConstants.ZERO); return dateTime.toDate(); }
Example 9
Source File: ScheduleHelper.java From ResearchStack with Apache License 2.0 | 5 votes |
public static Date nextSchedule(String cronString, Date lastExecution) { DateTime now = new DateTime(lastExecution); CronParser cronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX)); Cron cron = cronParser.parse(cronString); ExecutionTime executionTime = ExecutionTime.forCron(cron); DateTime nextExecution = executionTime.nextExecution(now); return nextExecution.toDate(); }
Example 10
Source File: JodaTimeConverters.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public Date convert(DateTime source) { return source.toDate(); }
Example 11
Source File: BizEntity.java From java-platform with Apache License 2.0 | 4 votes |
@Override public void setCreatedDate(final DateTime createdDate) { this.createdDate = null == createdDate ? null : createdDate.toDate(); }
Example 12
Source File: DateConvertor.java From stategen with GNU Affero General Public License v3.0 | 4 votes |
public Date convert(String source) { if (StringUtil.isEmpty(source)) { return null; } source = source.trim(); if (StringUtil.isNotEmpty(source)){ int length = source.length(); if (length==10){ if (UNIX_PATTERN.matcher(source).find()){ return new Date(Long.parseLong(source)*1000); } } if (length==13){ if (UNIX_PATTERN_MILLS.matcher(source).find()){ return new Date(Long.parseLong(source)); } } for (Entry<Pattern, SimpleDateFormat> dateEntry : DATE_PATTERN_FORMAT_MAP.entrySet()) { Pattern datePattern = dateEntry.getKey(); Matcher dateMatcher = datePattern.matcher(source); if (dateMatcher.find()) { String dateStr = dateMatcher.group(); try { SimpleDateFormat yearFormat = dateEntry.getValue(); Date date = yearFormat.parse(dateStr); DateTime dateTime = new DateTime(date); String timeStr = source.substring(dateMatcher.end()); dateTime = parserMills(dateTime, timeStr, 0, TIME_PATTERN_FORMAT_MAP, MIC_PATTERN_FORMAT_MAP); return dateTime.toDate(); } catch (ParseException e) { logger.error("", e); } break; } } } return null; }
Example 13
Source File: Jodatime.java From maven-framework-project with MIT License | 4 votes |
/** * 与jdk的时间转换 */ public static void convertJDK(){ System.out.println("-------------与jdk的时间转换-----------------"); DateTime dt = new DateTime(); //转换成java.util.Date对象 Date d1 = new Date(dt.getMillis()); Date d2 = dt.toDate(); //转换成java.util.Calendar对象 Calendar c1 = Calendar.getInstance(); c1.setTimeInMillis(dt.getMillis()); Calendar c2 = dt.toCalendar(Locale.getDefault()); }
Example 14
Source File: MinuteTimeCalculator.java From liteflow with Apache License 2.0 | 4 votes |
@Override public Date getStartTime() { DateTime dateTime = new DateTime(time); dateTime = dateTime.withSecondOfMinute(CommonConstants.ZERO); return dateTime.toDate(); }
Example 15
Source File: DateTimeUtil.java From DrivingAgency with MIT License | 4 votes |
public static Date strToDate(String dateTimeStr){ DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(STANDARD_FORMAT); DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr); return dateTime.toDate(); }
Example 16
Source File: TrackedEntityInstanceServiceTest.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void setUpTest() { organisationUnit = createOrganisationUnit( 'A' ); organisationUnitService.addOrganisationUnit( organisationUnit ); OrganisationUnit organisationUnitB = createOrganisationUnit( 'B' ); organisationUnitService.addOrganisationUnit( organisationUnitB ); entityInstanceAttribute = createTrackedEntityAttribute( 'A' ); attributeService.addTrackedEntityAttribute( entityInstanceAttribute ); entityInstanceA1 = createTrackedEntityInstance( organisationUnit ); entityInstanceB1 = createTrackedEntityInstance( organisationUnit ); entityInstanceB1.setUid( "UID-B1" ); programA = createProgram( 'A', new HashSet<>(), organisationUnit ); programService.addProgram( programA ); ProgramStage stageA = createProgramStage( 'A', programA ); stageA.setSortOrder( 1 ); programStageService.saveProgramStage( stageA ); Set<ProgramStage> programStages = new HashSet<>(); programStages.add( stageA ); programA.setProgramStages( programStages ); programService.updateProgram( programA ); DateTime enrollmentDate = DateTime.now(); enrollmentDate.withTimeAtStartOfDay(); enrollmentDate = enrollmentDate.minusDays( 70 ); DateTime incidenDate = DateTime.now(); incidenDate.withTimeAtStartOfDay(); programInstanceA = new ProgramInstance( enrollmentDate.toDate(), incidenDate.toDate(), entityInstanceA1, programA ); programInstanceA.setUid( "UID-A" ); programInstanceA.setOrganisationUnit( organisationUnit ); programStageInstanceA = new ProgramStageInstance( programInstanceA, stageA ); programInstanceA.setUid( "UID-PSI-A" ); programInstanceA.setOrganisationUnit( organisationUnit ); }
Example 17
Source File: CurrentQuarterGuavaTest.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void current_quarter_begin_date () { DateTime firstQuarterCheck = new DateTime(2013, 1, 15, 0, 0, 0, 0); CurrentQuarterGuava currentQuarterWithGuava = new CurrentQuarterGuava(firstQuarterCheck.toDate()); assertEquals(quarterBeginDate.toDate(), currentQuarterWithGuava.getQuarterBeginDate()); }
Example 18
Source File: DateCalculator.java From AsuraFramework with Apache License 2.0 | 3 votes |
/** * 获取指定日期偏移多少周后的此周第一天 * 注意:周一是一周的第一天 * * @param date 指定日期为标准 * @param week 偏移周数,正数:往后指定周数量,负数:往前指定周数量 * @return */ public static Date getFirstDayOfWeek(@NotNull Date date, int week) { Objects.requireNonNull(date, "date must not null"); DateTime dateTime = new DateTime(date); dateTime = dateTime.plusWeeks(week).dayOfWeek().withMinimumValue(); return dateTime.toDate(); }
Example 19
Source File: DateUtil.java From Mycat2 with GNU General Public License v3.0 | 2 votes |
/** * 根据日期字符串和日期格式解析得到date类型日期 * @param dateStr * @param datePattern * @return * @throws ParseException */ public static Date parseDate(String dateStr, String datePattern) throws ParseException { DateTime dt = DateTimeFormat.forPattern(datePattern).parseDateTime(dateStr); return dt.toDate(); }