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.code2040.bofashola.DatingGame.java

private static String getISO(String dateStamp, long seconds) {
    String str = "";

    //parse the datestamp string
    String date = dateStamp.split("T")[0];
    String time = dateStamp.split("T")[1];
    int year = Integer.valueOf(date.split("-")[0]);
    int month = Integer.valueOf(date.split("-")[1]);
    int dat = Integer.valueOf(date.split("-")[2]);
    int hrs = Integer.valueOf(time.split(":")[0]);
    int minute = Integer.valueOf(time.split(":")[1]);
    String secTemp = (time.split(":")[2]);
    int sec = Integer.valueOf(secTemp.charAt(0) + "" + secTemp.charAt(1));
    DateTime dt = new DateTime(year, month, dat, hrs, minute, sec);
    //Convert the string to milliseconds and add the interval in milliseconds
    long timeInMills = dt.getMillis() + getMilliseconds(seconds);
    DateTime newtime = new DateTime(timeInMills);
    //Use the Joda Time API and change it to ISO 8061 format
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    str = fmt.print(newtime);/*from   w w  w .ja va2  s  .  c  o  m*/
    return str.replace(str.substring(23, str.length()), "Z");
}

From source file:com.codereligion.cherry.junit.joda.TimeMachine.java

License:Apache License

/**
 * Goes to and stays at the specified {@link org.joda.time.DateTime}.
 *
 * @param dateTime the object which specifies the date and time to go to and stay
 *//*  w  w w .j  a  va 2s .  c o  m*/
public void goToAndStayAt(final DateTime dateTime) {

    checkArgument(dateTime != null, "dateTime must not be null.");

    DateTimeUtils.setCurrentMillisFixed(dateTime.getMillis());
}

From source file:com.cognifide.aet.cleaner.processors.filters.SuiteRemoveCondition.java

License:Apache License

private Long getRemoveTimestamp(CleanerContext cleanerContext) {
    Long removeBeforeTimestamp = null;
    if (cleanerContext.getRemoveOlderThan() != null) {
        DateTime dateTime = new DateTime().minusDays(cleanerContext.getRemoveOlderThan().intValue());
        removeBeforeTimestamp = dateTime.getMillis();
    }//from   ww  w. j a  v  a  2  s .c  o m
    return removeBeforeTimestamp;
}

From source file:com.core.luciernagasfx.FireflyController.java

private void runFirefly(final String op1, final String op2, final String op3, final String operation,
        final int firefliesNumber, final int iterationNumber) {
    Service<Void> service = new Service<Void>() {
        @Override/*from w w w.  j av a 2s .  co  m*/
        protected Task<Void> createTask() {
            return new Task<Void>() {
                @Override
                protected Void call() throws Exception {
                    //Background work                       
                    final CountDownLatch latch = new CountDownLatch(1);
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                DateTime begin = new DateTime();

                                //FX Stuff done here
                                Programa p = new Programa();
                                p.setOperacion(operation);
                                p.setPalabra1(op1.toCharArray());
                                p.setPalabra2(op2.toCharArray());
                                p.setPalabra3(op3.toCharArray());
                                p.setCantLuciernagas(firefliesNumber);
                                p.setIteracionesEjecucion(iterationNumber);

                                int i = 0;
                                boolean solucion = false;

                                try {
                                    while (p.getLuciernagaSolucion() == null && i < iterationNumber) {
                                        p.programa();
                                        i++;
                                    }
                                } catch (ArrayIndexOutOfBoundsException e) {
                                    Alert alert = new Alert(AlertType.ERROR);
                                    alert.setTitle("Too many values to search");
                                    alert.setHeaderText("Look, you just can put 10 distincts values");
                                    alert.setContentText("Try again changing your inputs words");

                                    alert.showAndWait();
                                }

                                DateTime end = new DateTime();

                                if (p.getLuciernagaSolucion() != null) {

                                    Formatter fmt = new Formatter();
                                    fmt.format("%1$-30.30s  %2$30s%n", "Operation: ",
                                            operation_combo.getSelectionModel().getSelectedItem().toString());
                                    fmt.format("%1$-30.30s  %2$30s%n", "First operator: ",
                                            p.getLuciernagaSolucion().getValPalabra1() + " (" + op1 + ")");
                                    fmt.format("%1$-30.30s  %2$30s%n", "Second operator: ",
                                            p.getLuciernagaSolucion().getValPalabra2() + " (" + op2 + ")");
                                    fmt.format("%1$-30.30s  %2$30s%n", "Result: ",
                                            p.getLuciernagaSolucion().getValPalabra3() + " (" + op3 + ")");
                                    fmt.format("%1$-30.30s  %2$30s%n", "Solution found at iteration: ",
                                            p.getMejores().size() - 1);
                                    fmt.format("%1$-30.30s%n",
                                            "--------------------------------------------------------------");
                                    fmt.format("%1$-30.30s  %2$30s%n", "Time to solve: ",
                                            (end.getMillis() - begin.getMillis()) + "ms");
                                    //Show results into textarea
                                    result_textarea.setText(fmt.toString());
                                    //Show grapfics into charts
                                    plotCharts(p);
                                } else {
                                    result_textarea.setText("Solution not found \nTime searching: "
                                            + (end.getMillis() - begin.getMillis()) + "ms");
                                }

                            } catch (IOException ex) {
                                Logger.getLogger(FireflyController.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (URISyntaxException ex) {
                                Logger.getLogger(FireflyController.class.getName()).log(Level.SEVERE, null, ex);
                            } finally {
                                latch.countDown();
                            }
                        }
                    });
                    latch.await();
                    //Keep with the background work
                    return null;
                }
            };
        }
    };
    service.start();
}

From source file:com.court.controller.OldLoansFxmlController.java

private boolean validateGDateWithInstallments(LocalDate value, TextField last_paid_ins) {

    int installments = Integer.parseInt(last_paid_ins.getText());
    Date gDate = Date.valueOf(value);

    DateTime calculatedDate = new DateTime(gDate.getTime()).plusMonths(installments);
    DateTime now = new DateTime();
    long diff = calculatedDate.getMillis() - now.getMillis();
    System.out.println("calculatedDate - " + calculatedDate);
    System.out.println("nowDate - " + now);
    System.out.println("difference - " + diff);
    return diff <= 0;
}

From source file:com.ctp.data.service.CsvTicksLoader.java

License:Open Source License

/**
 * @return a time series from Apple Inc. ticks.
 *///from   w ww  .  j  a va  2 s. c o  m
public static TimeSeries loadAppleIncSeries() {

    InputStream stream = CsvTicksLoader.class.getClassLoader().getResourceAsStream("rb1610.csv");

    List<Tick> ticks = new ArrayList<Tick>();

    CSVReader csvReader = new CSVReader(new InputStreamReader(stream, Charset.forName("UTF-8")), ',', '"', 1);
    try {
        String[] line;
        while ((line = csvReader.readNext()) != null) {
            DateTime date = new DateTime(DATE_FORMAT.parse(line[0]));
            double open = Double.parseDouble(line[1]);
            double high = Double.parseDouble(line[2]);
            double low = Double.parseDouble(line[3]);
            double close = Double.parseDouble(line[4]);
            double volume = Double.parseDouble(line[5]);
            double openInterest = Double.parseDouble(line[6]);
            OHLCData15Minute item = new OHLCData15Minute();
            item.setOpenPrice(open);
            item.setClosePrice(close);
            item.setHighPrice(high);
            item.setLowPrice(low);
            item.setVolume(volume);
            item.setId(date.getMillis());
            item.setInstrumentId("rb1610");
            item.setOpenInterest(openInterest);
            item.setDateTimeStr(line[0]);
            oHLCDataService.save(item);
            ticks.add(new Tick(date, open, high, low, close, volume));
        }
    } catch (IOException ioe) {
        Logger.getLogger(CsvTicksLoader.class.getName()).log(Level.SEVERE, "Unable to load ticks from CSV",
                ioe);
    } catch (ParseException pe) {
        Logger.getLogger(CsvTicksLoader.class.getName()).log(Level.SEVERE, "Error while parsing date", pe);
    } catch (NumberFormatException nfe) {
        Logger.getLogger(CsvTicksLoader.class.getName()).log(Level.SEVERE, "Error while parsing value", nfe);
    }

    return new TimeSeries("apple_ticks", ticks);
}

From source file:com.cubeia.games.poker.tournament.configuration.TournamentSchedule.java

License:Open Source License

/**
 * Calculate a list, limited by max, of tournament start times after the given date.
 * /* www  .  ja  v a  2 s  .  com*/
 * @param startTime date to start calculation from
 * @param max max number of start dates to calculate
 * @return list of start dates, never null
 */
public List<DateTime> calculateStartTimes(DateTime startTime, int max) {
    Trigger trigger = getSchedule();
    List<DateTime> startTimes = new ArrayList<>();
    Date time = new Date(startTime.getMillis());

    while (time != null && startTimes.size() < max) {
        time = trigger.getFireTimeAfter(time);
        if (time != null) {
            startTimes.add(new DateTime(time));
        }
    }

    return startTimes;
}

From source file:com.daemon.database.SearchTerm.java

License:Open Source License

/**
 * Checks all search terms and returns only these we consider searchable. Starts a new iteration if the 
 * updatecurrentstart is set to true. A searchable term if it is either a) in the middle of a iteration
 * or b) we have waited long enough(>= interval length).
 *  /*from   www .ja v  a 2  s.c  om*/
 * @param updateCurrentStart set true if we should also start a new iteration if possible
 * @return  true if we are in the middle of a active iteration or its has waited long enough
 *          false else
 *          
 */
public boolean isSearchable(boolean updateCurrentStart) {
    // Check if we are in a iteration
    if (getLastFetchedTweetId() == null) {
        // We are not in the middle of an iteration
        if (getOldStart() != null) {
            // We have an old start date, so we now have to check if we
            // have waited long enough
            DateTime oldStart = getOldStart();
            DateTime now = new DateTime();

            // Check for interval length constraint
            if ((now.getMillis() - oldStart.getMillis()) >= getIntervalLength().getMillis()) {
                // Start a new iteration if updatecurrentstart set to true
                if (updateCurrentStart) {
                    setCurrentStart(now);
                }
                return true;
            }
            // else: we haven't waited long enough
        } else {
            // This is the very first iteration of the search term, so add it regardless of
            // interval length
            return true;
        }
    } else { // We are in the middle of an iteration, so add the search term
        return true;
    }
    // failed all checks, not searchable
    return false;
}

From source file:com.daemon.Minion.java

License:Open Source License

/**
 * Tests whether the date of the tweet is older than the given old starting date.
 * @param tweetDate The date of the tweet to be tested.
 * @param oldStart The date to be checked against.
 * @return True, if the tweet date is older than the date of old start.
 *///from w ww  .  j a  va 2  s .  com
public static boolean tweetIsTooOld(DateTime tweetDate, DateTime oldStart) {
    return tweetDate.minus(oldStart.getMillis()).getMillis() < 0;
}

From source file:com.dataartisans.timeoutmonitoring.TimestampExtractorFunction.java

License:Apache License

@Override
public Long apply(JSONObject jsonObject) {
    String timestamp = jsonObject.optString(timestampField);

    if (timestamp == null) {
        return Long.MIN_VALUE;
    } else {/*from  ww w .j av  a 2s  . c o  m*/
        DateTime dateTime = formatter.parseDateTime(timestamp);
        return dateTime.getMillis();
    }
}