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:gov.usgs.anss.query.filefactory.SacHeaders.java

License:Open Source License

public static SacTimeSeries setEventHeader(SacTimeSeries sac, DateTime eventOrigin, Double eventLat,
        Double eventLon, Double eventDepth, Double eventMag, int sacMagType, int sacEventType) {

    if (eventLat == null) {
        eventLat = -12345.0;//from ww  w  .jav a2 s  .  co m
    }

    if (eventLon == null) {
        eventLon = -12345.0;
    }

    if (eventDepth == null) {
        eventDepth = -12345.0;
    }

    if (eventMag == null) {
        eventMag = -12345.0;
    }

    // SAC stores year day (nzjday) but not month and day.  
    DateTime start = new DateTime(sac.nzyear, 1, 1, sac.nzhour, sac.nzmin, sac.nzsec, sac.nzmsec,
            DateTimeZone.UTC);
    start = start.withDayOfYear(sac.nzjday);

    double timeDiff = (start.getMillis() - eventOrigin.getMillis()) / 1000.0d;

    sac.nzyear = eventOrigin.getYear();
    sac.nzjday = eventOrigin.getDayOfYear();
    sac.nzhour = eventOrigin.getHourOfDay();
    sac.nzmin = eventOrigin.getMinuteOfHour();
    sac.nzsec = eventOrigin.getSecondOfMinute();
    sac.nzmsec = eventOrigin.getMillisOfSecond();

    sac.b = sac.b + timeDiff;
    sac.e = sac.e + timeDiff;

    sac.iztype = SacTimeSeries.IO;

    sac.evla = eventLat;
    sac.evlo = eventLon;
    sac.evdp = eventDepth;
    sac.mag = eventMag;
    sac.imagtyp = sacMagType;
    sac.ievtyp = sacEventType;

    sac.lcalda = 1;

    return sac;
}

From source file:influent.server.dataaccess.DataAccessHelper.java

License:MIT License

public static String format(DateTime dateTime) {

    if (dateTime == null) {
        return null;
    }//  w w w.  java 2 s. co m

    StringBuilder s = new StringBuilder(10);

    s.append(dateTime.getYear());
    s.append('-');

    pad00(dateTime.getMonthOfYear(), s);
    s.append('-');

    pad00(dateTime.getDayOfMonth(), s);
    s.append(' ');

    pad00(dateTime.getHourOfDay(), s);
    s.append(':');

    pad00(dateTime.getMinuteOfHour(), s);
    s.append(':');

    pad00(dateTime.getSecondOfMinute(), s);
    s.append('.');

    int ms = dateTime.getMillisOfSecond();

    if (ms < 100) {
        s.append('0');
    }
    pad00(ms, s);

    return s.toString();
}

From source file:io.coala.xml.XmlUtil.java

License:Apache License

/**
 * @param date//  w  w w  .  j a  v a 2s . c o m
 * @return a JAXP {@link XMLGregorianCalendar}
 */
public static XMLGregorianCalendar toDateTime(final DateTime date) {
    final XMLGregorianCalendar result = getDatatypeFactory().newXMLGregorianCalendar();
    result.setYear(date.getYear());
    result.setMonth(date.getMonthOfYear());
    result.setDay(date.getDayOfMonth());
    result.setTime(date.getHourOfDay(), date.getMinuteOfHour(), date.getSecondOfMinute(),
            date.getMillisOfSecond());
    result.setTimezone(date.getZone().toTimeZone().getRawOffset() / 1000 / 60);
    // result.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
    return result;
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets hour./*w ww  .j  av  a2s  .  c  o  m*/
 *
 * @param moment    the moment
 * @param hourOfDay the hour of day
 * @return the hour
 */
public static DateTime setHour(DateTime moment, int hourOfDay) {
    return setTime(moment, hourOfDay, moment.getMinuteOfHour(), moment.getSecondOfMinute(),
            moment.getMillisOfSecond());
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets minute./*from w ww  .j  av  a2 s . c om*/
 *
 * @param moment       the moment
 * @param minuteOfHour the minute of hour
 * @return the minute
 */
public static DateTime setMinute(DateTime moment, int minuteOfHour) {
    return setTime(moment, moment.getHourOfDay(), minuteOfHour, moment.getSecondOfMinute(),
            moment.getMillisOfSecond());
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Sets second./*from w w  w .  j a  v a2  s  . c  o  m*/
 *
 * @param moment         the moment
 * @param secondOfMinute the second of minute
 * @return the second
 */
public static DateTime setSecond(DateTime moment, int secondOfMinute) {
    return setTime(moment, moment.getHourOfDay(), moment.getMinuteOfHour(), secondOfMinute,
            moment.getMillisOfSecond());
}

From source file:loci.formats.in.MetamorphReader.java

License:Open Source License

/** Converts a time value in milliseconds into a human-readable string. */
public static String decodeTime(int millis) {
    DateTime tm = new DateTime(millis, DateTimeZone.UTC);
    String hours = intFormat(tm.getHourOfDay(), 2);
    String minutes = intFormat(tm.getMinuteOfHour(), 2);
    String seconds = intFormat(tm.getSecondOfMinute(), 2);
    String ms = intFormat(tm.getMillisOfSecond(), 3);

    return hours + ":" + minutes + ":" + seconds + ":" + ms;
}

From source file:net.stickycode.scheduled.aligned.AlignedPeriodicSchedule.java

License:Open Source License

/**
 * The delay in seconds to wait before the initial execution to align the schedule as specified.
 * <b>An alignment of 0 means there is no delay</b>
 * <p>//from   w w w. jav  a 2s. c  om
 * e.g.
 * <ul>
 * <li>if the user configured a schedule as 'every hour at 15 minutes past'</li>
 * <li>and the service started at 10 minutes past</li>
 * <li>then the period would be 60 * 60 seconds</li>
 * <li>and the delay would be 5 * 60 seconds such that the first execution is 15 minutes past</li>
 * </ul>
 * </p>
 */
@Override
public long getInitialDelay() {
    if (alignment == 0)
        return 0;

    DateTime time = new DateTime();
    switch (alignmentUnit) {
    case HOURS:
        return calculateDelay(time.getHourOfDay(), alignment, 24);

    case MINUTES:
        return calculateDelay(time.getMinuteOfHour(), alignment, 60);

    case SECONDS:
        return calculateDelay(time.getSecondOfMinute(), alignment, 60);

    case MILLISECONDS:
        return calculateDelay(time.getMillisOfSecond(), alignment, 1000);

    default:
        throw new AlignmentNotSupportedException(alignmentUnit);
    }
}

From source file:nl.mpi.oai.harvester.cycle.EndpointAdapter.java

License:Open Source License

@Override
public void doneHarvesting(Boolean done) {

    /* Store the current date in a XMLGregorianCalendar object. Note: at
       the XML level, the date will be represented in ISO8601 format.
     *//*ww  w. ja va 2  s .  c  o m*/
    XMLGregorianCalendar xmlGregorianCalendar;

    try {
        // get current time in the UTC zone
        DateTime dateTime = new DateTime(DateTimeZone.UTC);

        // create XML calendar
        xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar();

        // set the date related fields
        xmlGregorianCalendar.setDay(dateTime.getDayOfMonth());
        xmlGregorianCalendar.setMonth(dateTime.getMonthOfYear());
        xmlGregorianCalendar.setYear(dateTime.getYear());

        // set the calendar to UTC, this zone sets off 0 minutes from UTC
        xmlGregorianCalendar.setTimezone(0);

        // set the time related fields
        xmlGregorianCalendar.setHour(dateTime.getHourOfDay());
        xmlGregorianCalendar.setMinute(dateTime.getMinuteOfHour());
        xmlGregorianCalendar.setSecond(dateTime.getSecondOfMinute());

        // represent milliseconds as a fraction of a second
        BigDecimal s = BigDecimal.valueOf(dateTime.getMillisOfSecond());
        s = s.divide(BigDecimal.valueOf(1000));

        xmlGregorianCalendar.setFractionalSecond(s);

        // set the property representing the date of the attempt
        endpointType.setAttempted(xmlGregorianCalendar);

        if (done) {
            // successful attempt, also set attribute representing this
            endpointType.setHarvested(xmlGregorianCalendar);
        }

        xmlOverview.save();

    } catch (DatatypeConfigurationException e) {
        // report the error, we cannot continue
        Logger.getLogger(EndpointAdapter.class.getName()).log(Level.SEVERE, null, endpointType);
    }
}

From source file:op.tools.SYSCalendar.java

License:Open Source License

/**
 * determines to which timeofday code a given date object belongs. The settings in SYSProps are taken into account.
 * or in short: it answers a question like "is 0800h early, noon or early in the morning ?"
 *
 * @param date/*w ww.  j  ava 2s. c o m*/
 * @return timecode
 */
public static byte whatTimeIDIs(Date date) {
    byte timeid;

    DateTimeFormatter parser = DateTimeFormat.forPattern("HH:mm");

    DateTime early_in_the_morning = parser
            .parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_EARLY_IN_THE_MORNING));
    DateTime morning = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_MORNING));
    DateTime noon = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_NOON));
    DateTime afternoon = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_AFTERNOON));
    DateTime evening = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_EVENING));
    DateTime late_at_night = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_LATE_AT_NIGHT));

    Period period_early_in_the_morning = new Period(early_in_the_morning.getHourOfDay(),
            early_in_the_morning.getMinuteOfHour(), early_in_the_morning.getSecondOfMinute(),
            early_in_the_morning.getMillisOfSecond());
    Period period_morning = new Period(morning.getHourOfDay(), morning.getMinuteOfHour(),
            morning.getSecondOfMinute(), morning.getMillisOfSecond());
    Period period_noon = new Period(noon.getHourOfDay(), noon.getMinuteOfHour(), noon.getSecondOfMinute(),
            noon.getMillisOfSecond());
    Period period_afternoon = new Period(afternoon.getHourOfDay(), afternoon.getMinuteOfHour(),
            afternoon.getSecondOfMinute(), afternoon.getMillisOfSecond());
    Period period_evening = new Period(evening.getHourOfDay(), evening.getMinuteOfHour(),
            evening.getSecondOfMinute(), evening.getMillisOfSecond());
    Period period_late_at_night = new Period(late_at_night.getHourOfDay(), late_at_night.getMinuteOfHour(),
            late_at_night.getSecondOfMinute(), late_at_night.getMillisOfSecond());

    DateTime ref = new DateTime(date);
    DateTime eitm = new DateMidnight(date).toDateTime().plus(period_early_in_the_morning);
    DateTime m = new DateMidnight(date).toDateTime().plus(period_morning);
    DateTime n = new DateMidnight(date).toDateTime().plus(period_noon);
    DateTime a = new DateMidnight(date).toDateTime().plus(period_afternoon);
    DateTime e = new DateMidnight(date).toDateTime().plus(period_evening);
    DateTime lan = new DateMidnight(date).toDateTime().plus(period_late_at_night);

    if (eitm.compareTo(ref) <= 0 && ref.compareTo(m) < 0) {
        timeid = DFNTools.BYTE_EARLY_IN_THE_MORNING;
    } else if (m.compareTo(ref) <= 0 && ref.compareTo(n) < 0) {
        timeid = DFNTools.BYTE_MORNING;
    } else if (n.compareTo(ref) <= 0 && ref.compareTo(a) < 0) {
        timeid = DFNTools.BYTE_NOON;
    } else if (a.compareTo(ref) <= 0 && ref.compareTo(e) < 0) {
        timeid = DFNTools.BYTE_AFTERNOON;
    } else if (e.compareTo(ref) <= 0 && ref.compareTo(lan) < 0) {
        timeid = DFNTools.BYTE_EVENING;
    } else {
        timeid = DFNTools.BYTE_LATE_AT_NIGHT;
    }
    return timeid;
}