Example usage for org.joda.time DateTime getMillisOfSecond

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

Introduction

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

Prototype

public int getMillisOfSecond() 

Source Link

Document

Get the millis of second field value.

Usage

From source file:cherry.goods.util.JodaTimeUtil.java

License:Apache License

/**
 * @param dtm ???{@link DateTime}/*from  www  .j a v a  2s.c om*/
 * @return ?????{@link Calendar}(?{@link DateTime}??)????????????
 */
public static Calendar getCalendar(DateTime dtm) {
    Calendar cal = Calendar.getInstance(dtm.getZone().toTimeZone());
    cal.set(dtm.getYear(), dtm.getMonthOfYear() - 1, dtm.getDayOfMonth(), dtm.getHourOfDay(),
            dtm.getMinuteOfHour(), dtm.getSecondOfMinute());
    cal.set(MILLISECOND, dtm.getMillisOfSecond());
    return cal;
}

From source file:com.almende.eve.agent.google.GoogleCalendarAgent.java

License:Apache License

/**
 * Quick create an event./*from  w  w  w .j  a v a  2  s.c  o m*/
 * 
 * @param start
 *            the start
 * @param end
 *            the end
 * @param summary
 *            the summary
 * @param location
 *            the location
 * @param calendarId
 *            the calendar id
 * @return the object node
 * @throws Exception
 *             the exception
 */
public ObjectNode createEventQuick(@Optional @Name("start") String start, @Optional @Name("end") String end,
        @Optional @Name("summary") final String summary, @Optional @Name("location") final String location,
        @Optional @Name("calendarId") final String calendarId) throws Exception {
    final ObjectNode event = JOM.createObjectNode();

    if (start == null) {
        // set start to current time, rounded to hours
        DateTime startDate = DateTime.now();
        startDate = startDate.plusHours(1);
        startDate = startDate.minusMinutes(startDate.getMinuteOfHour());
        startDate = startDate.minusSeconds(startDate.getSecondOfMinute());
        startDate = startDate.minusMillis(startDate.getMillisOfSecond());
        start = startDate.toString();
    }
    final ObjectNode startObj = JOM.createObjectNode();
    startObj.put("dateTime", start);
    event.put("start", startObj);
    if (end == null) {
        // set end to start +1 hour
        final DateTime startDate = new DateTime(start);
        final DateTime endDate = startDate.plusHours(1);
        end = endDate.toString();
    }
    final ObjectNode endObj = JOM.createObjectNode();
    endObj.put("dateTime", end);
    event.put("end", endObj);
    if (summary != null) {
        event.put("summary", summary);
    }
    if (location != null) {
        event.put("location", location);
    }

    return createEvent(event, calendarId);
}

From source file:com.almende.eve.agent.MeetingAgent.java

License:Apache License

/**
 * Get the timestamp rounded to the next half hour
 * /*from   w ww. ja  v  a  2s .c o m*/
 * @return
 */
private DateTime getNextHalfHour() {
    DateTime next = DateTime.now();
    next = next.minusMillis(next.getMillisOfSecond());
    next = next.minusSeconds(next.getSecondOfMinute());

    if (next.getMinuteOfHour() > 30) {
        next = next.minusMinutes(next.getMinuteOfHour());
        next = next.plusMinutes(60);
    } else {
        next = next.minusMinutes(next.getMinuteOfHour());
        next = next.plusMinutes(30);
    }

    return next;
}

From source file:com.almende.pi5.common.agents.GraphAgent.java

License:Apache License

/**
 * Update time./*from w  w  w.  j  av  a  2  s .  c  o  m*/
 */
@Access(AccessType.PUBLIC)
public void updateTime() {
    DateTime now = DateTime.now();
    now = now.plus((TIMESTEP - (now.getMinuteOfHour() % TIMESTEP)) * 60000 - (now.getSecondOfMinute() * 1000)
            - now.getMillisOfSecond());
    if (!this.currentTimeslot.equals(now)) {
        this.currentTimeslot = now;
        LOG.fine(getId() + ": updateTime to: " + now);
    }
}

From source file:com.altoukhov.svsync.FileSnapshot.java

License:Apache License

public FileSnapshot(String name, long size, DateTime lastModified, String relativePath) {
    this.fileName = name;
    this.fileSize = size;
    this.modifiedTimestamp = lastModified.minusMillis(lastModified.getMillisOfSecond());
    this.relativePath = relativePath;
}

From source file:com.barchart.feed.test.replay.DDFLogDeframer.java

License:BSD License

static final void encodeTimeStamp(final String timestamp, final ByteBuffer buffer) {

    DateTime dateTime = timeParser.parseDateTime(timestamp);

    // base fields
    buffer.put(DDF_CENTURY); // century
    buffer.put(encodeTimeStampByte(dateTime.getYearOfCentury())); // year
    buffer.put(encodeTimeStampByte(dateTime.getMonthOfYear())); // month
    buffer.put(encodeTimeStampByte(dateTime.getDayOfMonth())); // day
    buffer.put(encodeTimeStampByte(dateTime.getHourOfDay())); // hours
    buffer.put(encodeTimeStampByte(dateTime.getMinuteOfHour())); // minutes
    buffer.put(encodeTimeStampByte(dateTime.getSecondOfMinute())); // seconds

    // milliseconds
    final int millisOfSecond = dateTime.getMillisOfSecond();
    buffer.put((byte) (millisOfSecond & 0xFF)); // low byte
    buffer.put((byte) ((millisOfSecond >>> 8) & 0xFF)); // high byte

}

From source file:com.collective.celos.Util.java

License:Apache License

public static boolean isFullSecond(DateTime dt) {
    return dt.getMillisOfSecond() == 0;
}

From source file:com.github.autermann.matlab.value.MatlabDateTime.java

License:Open Source License

public double[] toArray() {
    DateTime utc = time.toDateTime(DateTimeZone.UTC);
    return new double[] { (double) utc.getYear(), (double) utc.getMonthOfYear(), (double) utc.getDayOfMonth(),
            (double) utc.getHourOfDay(), (double) utc.getMinuteOfHour(),
            (double) utc.getSecondOfMinute() + (double) utc.getMillisOfSecond() / 1000, };

}

From source file:com.github.markserrano.jsonquery.jpa.util.DateTimeUtil.java

License:Apache License

public static Map<String, DateTime> getYesterdaySpan() {
    DateTime now = new DateTime();

    DateTime from = now.minusDays(1).minusHours(now.getHourOfDay()).minusMinutes(now.getMinuteOfHour())
            .minusSeconds(now.getSecondOfMinute()).minusMillis(now.getMillisOfSecond());

    DateTime to = from.plusHours(23).plusMinutes(59).plusSeconds(59);

    Map<String, DateTime> map = new HashMap<String, DateTime>();
    map.put("from", from);
    map.put("to", to);

    return map;//w ww  .j  a v  a 2  s  .co  m
}

From source file:com.google.cloud.dataflow.sdk.util.TimeUtil.java

License:Apache License

/**
 * Converts a {@link ReadableInstant} into a Dateflow API time value.
 *///from   ww  w  .  j  av  a2  s  .co m
public static String toCloudTime(ReadableInstant instant) {
    // Note that since Joda objects use millisecond resolution, we always
    // produce either no fractional seconds or fractional seconds with
    // millisecond resolution.

    // Translate the ReadableInstant to a DateTime with ISOChronology.
    DateTime time = new DateTime(instant);

    int millis = time.getMillisOfSecond();
    if (millis == 0) {
        return String.format("%04d-%02d-%02dT%02d:%02d:%02dZ", time.getYear(), time.getMonthOfYear(),
                time.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute());
    } else {
        return String.format("%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", time.getYear(), time.getMonthOfYear(),
                time.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(),
                millis);
    }
}