@Override public LocalDateTime convert(DateTime source) { return source.toLocalDateTime(); } }
@Override public LocalDateTime convert(DateTime source) { return source.toLocalDateTime(); } }
private Object getRandomValueForTimeColumn(boolean isSimpleDate) { long randomMs = ThreadLocalRandom.current().nextLong(startTime); long dateColVal = randomMs; Object result; if (isSimpleDate) { DateTime dateTime = new DateTime(randomMs); LocalDateTime localDateTime = dateTime.toLocalDateTime(); int year = localDateTime.getYear(); int month = localDateTime.getMonthOfYear(); int day = localDateTime.getDayOfMonth(); String dateColStr = String.format("%04d%02d%02d", year, month, day); dateColVal = Integer.valueOf(dateColStr); result = new Integer(Integer.valueOf(dateColStr)); } else { result = new Long(dateColVal); } if (dateColVal < minTime) { minTime = dateColVal; } if (dateColVal > maxTime) { maxTime = dateColVal; } return result; }
return null; return local.toLocalDateTime();
public LocalDateTime f( DateTime dateTime ) { return dateTime.toLocalDateTime(); } };
@Override public LocalDateTime fromNonNullValue(Timestamp value) { DateTime dateTime = new DateTime(value.getTime()); LocalDateTime localDateTime = dateTime.toLocalDateTime(); return localDateTime; }
String utcTime = "2016-06-17 14:22:02Z"; DateTimeFormatter parser = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ssZ"); DateTime dateTime = parser.parseDateTime(utcTime).withZone(DateTimeZone.forID("Asia/Kolkata")); DateTimeFormatter formatter = DateTimeFormat.forPattern("dd-MM-YYYY HH:mm:ss"); System.out.println(dateTime); LocalDateTime localDateTime = dateTime.toLocalDateTime(); String formattedlocalDateTime = formatter.print(localDateTime); System.out.println(formattedlocalDateTime);
@Test public void change_timezone_of_reminder() { DateTime originalReminderDateTime = LocalDateTime.parse("2015-05-15T15:00").toDateTime( DateTimeZone.forID("Europe/Berlin")); assertThat(originalReminderDateTime.toString(), equalTo("2015-05-15T15:00:00.000+02:00")); long reminderMillis = originalReminderDateTime.getMillis(); DateTime updatedTime = new DateTime(reminderMillis, DateTimeZone.forID("Europe/Berlin")) .withZoneRetainFields(DateTimeZone.forID("America/New_York")); assertThat(updatedTime.toLocalDateTime(), equalTo(LocalDateTime.parse("2015-05-15T15:00"))); assertThat(updatedTime.toString(), equalTo("2015-05-15T15:00:00.000-04:00")); }
//Assign utc calendar Calendar utc= Calendar.getInstance(); utc.setTimeZone(TimeZone.getTimeZone("UTC")); Timestamp timestamp = rs.getTimestamp("timestampcolumn", utc); //Convert to client date time DateTime dateTime = new DateTime(timestamp.getTime(), DateTimeZone.forID("Asia/Kolkata")); //Format DateTimeFormatter formatter = DateTimeFormat.forPattern("dd-MM-YYYY HH:mm:ss"); //Change to client wall clock time LocalDateTime localDateTime = dateTime.toLocalDateTime(); String formattedlocalDateTime = formatter.print(localDateTime)
DateTime dateTimePlus2 = DateTime.parse("2015-07-09T05:10:00+02:00"); System.out.println(dateTimePlus2); DateTime dateTimeUTC = dateTimePlus2.withZone(DateTimeZone.UTC); System.out.println(dateTimeUTC); LocalDateTime localDateTimeUTC = dateTimeUTC.toLocalDateTime(); System.out.println(localDateTimeUTC);
@Test public void testDateTimeConversion() { final Date sourceDateTime = new DateTime(2015, 3, 15, 12, 55, TIMEZONE_MOSCOW).toDate(); final Date expectedResult = new DateTime(2015, 3, 15, 12 - 2, 55, TIMEZONE_BERLIN).toLocalDateTime().toDate(); final DateTime timeInMoscow = new DateTime(sourceDateTime, TIMEZONE_MOSCOW); final DateTime timeInBerlin = timeInMoscow.toDateTime(TIMEZONE_BERLIN); final Date actualResult = timeInBerlin.toLocalDateTime().toDate(); Assert.assertEquals(expectedResult, actualResult); }
public static Date convertJodaTimezone(LocalDateTime date, String srcTz, String destTz) { DateTime srcDateTime = date.toDateTime(DateTimeZone.forID(srcTz)); DateTime dstDateTime = srcDateTime.withZone(DateTimeZone.forID(destTz)); return dstDateTime.toLocalDateTime().toDateTime().toDate(); }
public static LocalDateTime parseDateTimeFromJson(String value) { DateTime dateTime = parseDateString(value); if (dateTime != null) return dateTime.toLocalDateTime(); else // required to support datajs clients (although not spec compliant) return InternalUtil.parseDateTimeFromXml(value); }
public static Date convertJodaTimezone(LocalDateTime date, String localTimeZone, String destTimeZone) { DateTime srcDateTime = date.toDateTime(DateTimeZone.forID(localTimeZone)); DateTime dstDateTime = srcDateTime.withZone(DateTimeZone.forID(destTimeZone)); return dstDateTime.toLocalDateTime().toDateTime().toDate(); }
@Override public LocalDateTime sundayMidnight() { DateTime today = currentDateTime(); int dayIndex = today.getDayOfWeek() - 1; int dayOffset = 7 - dayIndex; DateTime monday = today.plusDays(dayOffset); DateTime mondayStart = monday.withTimeAtStartOfDay(); return mondayStart.toLocalDateTime(); }
public LocalDateTime convert(String value, Class<? extends LocalDateTime> type, ResourceBundle bundle) { try { DateTime out = new LocaleBasedJodaTimeConverter(localization).convert(value, shortDateTime()); if (out == null) { return null; } return out.toLocalDateTime(); } catch (Exception e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_datetime"), value)); } } }
return null; return local.toLocalDateTime();
private DateTime toDateTime(DataRange range, BoundaryPoint point) throws DaoException { String value = point.getValue(); URI fieldType = range.getPath().lastField().getFieldType(); if (fieldType.equals(XMLSchema.DATE) || fieldType.equals(XMLSchema.DATETIME)) { return new DateTime(value).toLocalDateTime().toDateTime(DateTimeZone.UTC); } throw new DaoException("Unsupported data type: " + fieldType.stringValue()); }
@Override protected Object[] toConvertedColumns(DateTime value) { return new Object[] { value.toLocalDateTime(), new DateTimeZoneWithOffset(value.getZone(), value.getZone().isFixed() ? null : DateTimeZone.forOffsetMillis(value.getZone().getOffset(value))) }; } }
@Override protected Object[] toConvertedColumns(DateTime value) { return new Object[] { value.toLocalDateTime(), new DateTimeZoneWithOffset(value.getZone(), value.getZone().isFixed() ? null : DateTimeZone.forOffsetMillis(value.getZone().getOffset(value))) }; } }