Example usage for org.joda.time DateTime getMillis

List of usage examples for org.joda.time DateTime getMillis

Introduction

In this page you can find the example usage for org.joda.time DateTime getMillis.

Prototype

public long getMillis() 

Source Link

Document

Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.

Usage

From source file:com.ufnet.ws.typehandler.DateTimeTypeHandler.java

License:Open Source License

/**
 * Convert DateTime to timestamp when save to database.
 *///w  w  w. j av a2  s. c  om
@Override
public void setNonNullParameter(PreparedStatement ps, int i, DateTime parameter, JdbcType jdbcType)
        throws SQLException {
    ps.setTimestamp(i, new Timestamp(parameter.getMillis()));
}

From source file:com.vaushell.superpipes.nodes.buffer.N_Buffer.java

License:Open Source License

private void pushMessage(final Message message) throws IOException {
    final DateTime now = new DateTime();

    final Duration delta;
    if (getProperties().containsKey("wait-min") && getProperties().containsKey("wait-max")) {
        final int waitMin = getProperties().getConfigInteger("wait-min");
        final int waitMax = getProperties().getConfigInteger("wait-max");

        if (waitMin == waitMax) {
            delta = new Duration((long) waitMin);
        } else {//from   w  ww  .j  ava2  s .  co  m
            delta = new Duration((long) (rnd.nextInt(waitMax - waitMin) + waitMin));
        }
    } else {
        delta = new Duration(0L);
    }

    final DateTime ID;
    if (messageIDs.isEmpty()) {
        ID = now.plus(delta);
    } else {
        final DateTime askedTime = now.plus(delta);

        final long lastID = messageIDs.last();
        final DateTime lastTime = new DateTime(lastID);

        if (askedTime.isBefore(lastTime)) {
            ID = lastTime.plusMillis(1);
        } else {
            ID = askedTime;
        }
    }

    final Path p = messagesPath.resolve(Long.toString(ID.getMillis()));

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("[" + getNodeID() + "] write message with ID=" + ID);
    }

    writeMessage(p, message);

    messageIDs.add(ID.getMillis());
}

From source file:com.webcohesion.enunciate.examples.gwt_json_overlay.schema.structures.DateTimeXmlAdapter.java

License:Apache License

public Date marshal(DateTime dateTime) throws Exception {
    return new Date(dateTime.getMillis());
}

From source file:com.weebly.opus1269.copyeverywhere.model.ClipContentProvider.java

License:Apache License

/**
 * Delete rows older than the storage duration
 *
 * @return Number of rows deleted/*from w  w w .j  av a 2s  . c om*/
 */
@SuppressWarnings("CallToStringEquals")
public static int deleteOldItems() {
    final String value = Prefs.getDuration();
    if (value.equals(Prefs.DEFAULT_DURATION)) {
        return 0;
    }

    final Context context = App.getContext();
    DateTime today = DateTime.now();
    today = today.withTimeAtStartOfDay();
    DateTime deleteDate = today;
    switch (value) {
    case "day":
        deleteDate = deleteDate.minusDays(1);
        break;
    case "week":
        deleteDate = deleteDate.minusWeeks(1);
        break;
    case "month":
        deleteDate = deleteDate.minusMonths(1);
        break;
    case "year":
        deleteDate = deleteDate.minusYears(1);
        break;
    default:
        return 0;
    }

    final long deleteTime = deleteDate.getMillis();

    // Select all non-favorites older than the calculated time
    final String selection = "(" + ClipContract.Clip.COL_FAV + " == 0 " + ")" + " AND ("
            + ClipContract.Clip.COL_DATE + " < " + deleteTime + ")";

    return context.getContentResolver().delete(ClipContract.Clip.CONTENT_URI, selection, null);
}

From source file:com.welflex.model.hibernate.DateTimeUserType.java

License:Apache License

public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    if (value == null) {
        st.setNull(index, Types.TIMESTAMP);
    } else {/*from   w w w.j  a va  2 s . co m*/
        DateTime dateTime = (DateTime) value;
        Timestamp timestamp = new Timestamp(dateTime.getMillis());
        st.setTimestamp(index, timestamp);
    }
}

From source file:com.wookler.server.river.MessageBlockBackup.java

License:Apache License

private long windowtime(File dir) throws BlockBackupException {
    String dts = windowdir(dir);/*  w w w . j  a  va  2 s  . c om*/

    if (!StringUtils.isEmpty(dts)) {
        try {
            DateTimeFormatter fmt = DateTimeFormat.forPattern(Constants.DIR_DATETIME_FORMAT);
            DateTime t = fmt.parseDateTime(dts);

            return t.getMillis();
        } catch (IllegalArgumentException e) {
            return -1;
        }
    }
    return -1;
}

From source file:com.xebia.devradar.GitHubFetcher.java

License:Apache License

private Event transformCommitToEvent(GithubCommitDTO githubCommitDTO) {
    DateTime dateTime = ISODateTimeFormat.dateTimeNoMillis().parseDateTime(githubCommitDTO.committed_date);
    return new Event(dateTime.getMillis(), githubCommitDTO.committer.name, githubCommitDTO.message,
            githubCommitDTO.committer.email);
}

From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java

License:Open Source License

/**
 * Creates a new Period instance that matches all the instants between N hours before the instantiation and the
 * instantiation.//from w w  w  .j  a  va 2  s.  c o  m
 * 
 * @param numberOfHours number of hours to substract from current date
 * @return The corresponding period object
 */
public static Period createSinceHoursPeriod(int numberOfHours) {
    DateTime dt = new DateTime();
    return createPeriod(dt.minusHours(numberOfHours).getMillis(), dt.getMillis());
}

From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java

License:Open Source License

/**
 * Creates a new Period instance that matches all the instants between N days before the instantiation and the
 * instantiation./*from  w ww .  jav  a 2  s .  c o m*/
 * 
 * @param numberOfDays number of days to substract from current date
 * @return The corresponding period object
 */
public static Period createSinceDaysPeriod(int numberOfDays) {
    DateTime dt = new DateTime();
    return createPeriod(dt.minusDays(numberOfDays).getMillis(), dt.getMillis());
}

From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java

License:Open Source License

/**
 * Creates a new Period instance that matches all the instants between N weeks before the instantiation and the
 * instantiation./*from ww w . j av  a 2s.c o m*/
 * 
 * @param numberOfWeeks number of weeks to substract from current date
 * @return The corresponding period object
 */
public static Period createSinceWeeksPeriod(int numberOfWeeks) {
    DateTime dt = new DateTime();
    return createPeriod(dt.minusWeeks(numberOfWeeks).getMillis(), dt.getMillis());
}