Java Code Examples for org.joda.time.DateTime#toDateTime()

The following examples show how to use org.joda.time.DateTime#toDateTime() . These examples are extracted from open source projects. 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 Project: commcare-android   File:    License: Apache License 2.0 6 votes vote down vote up
private void setAnswer() {
    if (getCurrentAnswer() != null) {

        //The incoming date is in Java Format, parsed from an ISO-8601 date.
        DateTime isoAnchoredDate =
                new DateTime(((Date)getCurrentAnswer().getValue()).getTime());

        //The java date we loaded doesn't know how to communicate its timezone offsets to
        //Joda if the offset for the datetime represented differs from what it is currently.
        //This is the case, for instance, in historical dates where timezones offsets were
        //different. This method identifies what offset the Java date actually was using.
        DateTimeZone correctedAbsoluteOffset =
                DateTimeZone.forOffsetMillis(-isoAnchoredDate.toDate().getTimezoneOffset() * 60 * 1000);

        //Then manually loads it back into a Joda datetime for manipulation
        DateTime adjustedDate = isoAnchoredDate.toDateTime(correctedAbsoluteOffset);

        mDatePicker.init(adjustedDate.getYear(), adjustedDate.getMonthOfYear() - 1, adjustedDate.getDayOfMonth(),
    } else {
        // create date widget with current time as of right now
Example 2
private String formatDateTimeToUTC(String originalTime) {
    DateTime dateTime = DateTime.parse(originalTime);

    // TODO: Remove workaround for Java SDK bug not returning time in UTC.
    try {
        dateTime = dateTime.toDateTime(DateTimeZone.UTC);
    } catch(Exception ex) {
        // Swallow exception and use date as-is.

    return dateTime.toString(DATE_FORMAT_STRING);
Example 3
Source Project: ipst   File:    License: Mozilla Public License 2.0 5 votes vote down vote up
public static DateTime toCetDate(DateTime date) {
    DateTimeZone cet = DateTimeZone.forID("CET");
    if (!date.getZone().equals(cet)) {
        return date.toDateTime(cet);
    return date;
Example 4
private static DateTime toCetDate(DateTime date) {
    DateTimeZone cet = DateTimeZone.forID("CET");
    if (!date.getZone().equals(cet)) {
        return date.toDateTime(cet);
    return date;
Example 5
public ClockSetRequestMessage(String MAC, DateTime stamp) {
    super(MAC, "");
    type = MessageType.CLOCK_SET_REQUEST;

    // Circles expect clock info to be in the UTC timezone
    this.stamp = stamp.toDateTime(DateTimeZone.UTC);
Example 6
Source Project: arctic-sea   File:    License: Apache License 2.0 4 votes vote down vote up
private DateTime checkTimeZone(DateTime time) {
    if (timeZone != null) {
        return time.toDateTime(timeZone);
    return time;
Example 7
Source Project: rya   File:    License: Apache License 2.0 4 votes vote down vote up
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings) throws QueryEvaluationException {
    final List<BindingSet> list = new ArrayList<>();
    try {
        final Collection<Event> searchEvents;
        final String subj;
        //if the provided binding set has the subject already, set it to the constant subject.
        if(!subjectConstant.isPresent() && bindings.hasBinding(subjectVar.get())) {
            subjectConstant = Optional.of(bindings.getValue(subjectVar.get()).stringValue());
        } else if(bindings.size() != 0) {

        // If the subject needs to be filled in, check if the subject variable is in the binding set.
        if(subjectConstant.isPresent()) {
            // if it is, fetch that value and then fetch the entity for the subject.
            subj = subjectConstant.get();
            searchEvents = RyaIRI(subj)), Optional.of(geoFilters), Optional.of(temporalFilters));
        } else {
            searchEvents =, Optional.of(geoFilters), Optional.of(temporalFilters));

        for(final Event event : searchEvents) {
            final MapBindingSet resultSet = new MapBindingSet();
            if(event.getGeometry().isPresent()) {
                final Geometry geo = event.getGeometry().get();
                final Value geoValue = VF.createLiteral(geo.toText());
                final Var geoObj = geoPattern.getObjectVar();
                resultSet.addBinding(geoObj.getName(), geoValue);

            final Value temporalValue;
            if(event.isInstant() && event.getInstant().isPresent()) {
                final Optional<TemporalInstant> opt = event.getInstant();
                DateTime dt = opt.get().getAsDateTime();
                dt = dt.toDateTime(DateTimeZone.UTC);
                final String str = dt.toString(TemporalInstantRfc3339.FORMATTER);
                temporalValue = VF.createLiteral(str);
            } else if(event.getInterval().isPresent()) {
                temporalValue = VF.createLiteral(event.getInterval().get().getAsPair());
            } else {
                temporalValue = null;

            if(temporalValue != null) {
                final Var temporalObj = temporalPattern.getObjectVar();
                resultSet.addBinding(temporalObj.getName(), temporalValue);
    } catch (final ObjectStorageException e) {
        throw new QueryEvaluationException("Failed to evaluate the binding set", e);
    return new CollectionIteration<>(list);