Example usage for org.joda.time DateTime toString

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

Introduction

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

Prototype

public String toString(String pattern) 

Source Link

Document

Output the instant using the specified format pattern.

Usage

From source file:isjexecact.br.com.inso.utils.Funcoes.java

/**
 * Retorna uma String com a data convertida no formato dd/MM/yyyy.            
 * @param data Data a ser convertida./*  w  w  w .  j a v a  2 s  .  com*/
 * @return String com a data convertida no formato dd/mm/yyyy.
 * @throws java.text.ParseException
 */
public static String getDataAmd(Date data) throws ParseException {
    if (data == null) {
        return null;
    }
    // Glauber 11/09/2014 - Estou trocando pelo componente joda-time para me livrar da dor de cabea de utiilzar as classes nativa do Java.
    DateTime dateTime = new DateTime(data);
    return dateTime.toString("dd/MM/YYYY");

    //        Calendar calendario = Calendar.getInstance();         
    //        calendario.setTime(data);        
    // Glauber 25/07/2014 - Estou somando +1 no ms, porque conforme documentao da Oracle o calendario Gregoriano(padro) o ms de janeiro  0.
    //        return  StrZero(calendario.get(Calendar.DAY_OF_MONTH),2) + "/" + StrZero(calendario.get(Calendar.MONTH)+1,2) + "/" + StrZero(calendario.get(Calendar.YEAR),4);

}

From source file:isjexecact.br.com.inso.utils.Funcoes.java

/**
 * Retorna uma String com a data convertida no formato yyyymmdd.            
 * @param data Data a ser convertida./*w w w .  j  a  v  a2 s. co m*/
 * @return String com a data convertida no formato yyyymmdd.
 */
public static String Dtos(Date data) {
    if (data == null) {
        return null;
    }
    // Glauber 11/09/2014 - Estou trocando pelo componente joda-time para me livrar da dor de cabea de utiilzar as classes nativa do Java.
    DateTime dateTime = new DateTime(data);
    return dateTime.toString("YYYYMMdd");

    //        Calendar calendario = new GregorianCalendar(); 
    //        calendario.setTime(data);        
    // Glauber 25/07/2014 - Estou somando +1 no ms, porque conforme documentao da Oracle o calendario Gregoriano(padro) o ms de janeiro  0.
    //        return  StrZero(calendario.get(Calendar.YEAR),4) +  StrZero(calendario.get(Calendar.MONTH)+1,2) + StrZero(calendario.get(Calendar.DAY_OF_MONTH),2);

}

From source file:it.elmariachistudios.mystorews.utils.DateTimeUtils.java

/**
 * Converte un timestamp nel formato necessario alla generazione del documento che rappresenta la domanda
 * @param date//from w  w w  . j ava  2 s . c  om
 * @return la data formattata
 */
public static String convertForDomandaITA(DateTime date) {
    if (date == null) {
        return "";
    }
    return date.toString(formatterDayITA);
}

From source file:it.elmariachistudios.mystorews.utils.DateTimeUtils.java

/**
 * Converte una data espressa in DateTime in una stringa nel formato YYYY-MM-dd
 * @param date/*from w  ww  .  j av  a2  s .  c om*/
 * @return una stringa con la data convertita
 */
public static String convertToString(DateTime date) {
    if (date == null) {
        return "";
    }
    return date.toString(formatter);
}

From source file:it.geosolutions.geobatch.destination.common.utils.TimeUtils.java

License:Open Source License

/**
 * Check if the time start with the date of today
 * /*w w w .  ja va2  s.co  m*/
 * @param time in a string format starting with a getDayFormatter()
 * @return
 */
public static boolean isToday(String time) {
    DateTime now = new DateTime();
    boolean isToday = false;
    if (time.startsWith(now.toString(TimeUtils.getDayFormatter()))) {
        isToday = true;
    }
    return isToday;
}

From source file:it.geosolutions.geobatch.destination.common.utils.TimeUtils.java

License:Open Source License

/**
 * @return String representation for now in timestamp
 *//* w ww  . jav  a 2 s  .c om*/
public static String getTodayTimestamp() {
    DateTime now = new DateTime();
    return (new Timestamp(getDefaultFormatter().parseMillis(now.toString(getDefaultFormatter())))).toString();
}

From source file:it_minds.dk.eindberetningmobil_android.service.MonitoringServiceReport.java

License:Mozilla Public License

/***
 * Creates an UI model to send to the listening activity.
 *
 * @param acc/*from  w  w  w. jav  a2 s. c  o  m*/
 * @param distance
 * @param time
 */
public void updateDisplay(float acc, double distance, DateTime time) {
    String s = DistanceDisplayer.formatDistance(distance);
    String distanceText = (s + " Km");//kilometer is an SI unit, so no translations is needed
    String timeText = "";
    if (time != null) {
        timeText = (time.toString("HH:mm:ss"));
    }
    String accText = DistanceDisplayer.formatAccuracy(acc) + " m";
    lastUiUpdate = new UiStatusModel(timeText, accText, distanceText);
    monitoringService.sendUiUpdate(lastUiUpdate);
}

From source file:jongo.JongoUtils.java

License:Open Source License

/**
 * Infers the java.sql.Types of the given String and returns the JDBC mappable Object corresponding to it.
 * The conversions are like this:/*  w w  w .  j a v  a2  s . co m*/
 * String -> String
 * Numeric -> Integer
 * Date or Time -> Date
 * Decimal -> BigDecimal
 * ??? -> TimeStamp
 * @param val a String with the value to be mapped
 * @return a JDBC mappable object instance with the value
 */
public static Object parseValue(String val) {
    Object ret = null;
    if (!StringUtils.isWhitespace(val) && StringUtils.isNumeric(val)) {
        try {
            ret = Integer.valueOf(val);
        } catch (Exception e) {
            l.debug(e.getMessage());
        }
    } else {
        DateTime date = JongoUtils.isDateTime(val);
        if (date != null) {
            l.debug("Got a DateTime " + date.toString(ISODateTimeFormat.dateTime()));
            ret = new java.sql.Timestamp(date.getMillis());
        } else {
            date = JongoUtils.isDate(val);
            if (date != null) {
                l.debug("Got a Date " + date.toString(ISODateTimeFormat.date()));
                ret = new java.sql.Date(date.getMillis());
            } else {
                date = JongoUtils.isTime(val);
                if (date != null) {
                    l.debug("Got a Time " + date.toString(ISODateTimeFormat.time()));
                    ret = new java.sql.Time(date.getMillis());
                }
            }
        }

        if (ret == null && val != null) {
            l.debug("Not a datetime. Try someting else. ");
            try {
                ret = new BigDecimal(val);
            } catch (NumberFormatException e) {
                l.debug(e.getMessage());
                ret = val;
            }
        }
    }
    return ret;
}

From source file:jp.co.ntt.atrs.domain.common.util.DateTimeUtil.java

License:Apache License

/**
 * (yyyy/MM/dd)???//from   w w  w  .  ja  va 2 s  .c o m
 * 
 * @param dateTime DateTime
 * @return (yyyy/MM/dd)
 */
public static String toFormatDateString(DateTime dateTime) {
    if (dateTime == null) {
        return "";
    }
    return dateTime.toString("yyyy/MM/dd");
}

From source file:jsattrak.gui.JTrackingPanel.java

License:Open Source License

/**
 * Requires that currentTime be set/*w  w  w  .  ja va2  s  . c om*/
 */
private void updateTime() {
    // if something's not set, erase all data
    if (gsComboBox.getSelectedIndex() < 0 || satComboBox.getSelectedIndex() < 0) {
        clearCurrTrackInfo();
        return;
    }

    if (currentSat.getTEMEPos() != null && !Double.isNaN(currentSat.getTEMEPos()[0])) {
        double[] aer = currentGs.calculate_AER(currentSat.getTEMEPos()); // TEME

        // add text AER and string
        timeLbl.setText(TIME_LBL_TXT + timeAsString);
        azLbl.setText(String.format("%s %.3f", AZ_LBL_TXT, aer[0]));
        elLbl.setText(String.format("%s %.3f", EL_LBL_TXT, aer[1]));
        rangeLbl.setText(String.format("%s %.3f", RANGE_LBL_TXT, aer[2]));

        // update polar plot
        polarPlotLbl.update(timeAsString, aer, currentGs.getElevationConst(), currentGs.getStationName(),
                currentSat.getName());

        // check to see if we need to update Lead/Lag data
        // no good J2000 positions not saved through time right now in
        // satprops
        // see if we even need to bother - lead data option selected in both
        // 2D and polar plot
        if (polarPlotLbl.isShowLeadLagData() && currentSat.isGroundTrackShown()) {
            boolean updateLeadData = false;
            boolean updateLagData = false;

            // need to update lead data?
            if (polarPlotLbl.getAerLead() == null || polarPlotLbl.getAerLead().length < 1) {
                updateLeadData = true;
                oldLeadX = currentSat.getTemePosLead()[0][0];
            } else if (oldLeadX != currentSat.getTemePosLead()[0][0]) {
                updateLeadData = true;
                oldLeadX = currentSat.getTemePosLead()[0][0];
            }

            // need to update lag data?
            if (polarPlotLbl.getAerLag() == null || polarPlotLbl.getAerLag().length < 1) {
                updateLagData = true;
                oldLagX = currentSat.getTemePosLag()[0][0];
            } else if (oldLagX != currentSat.getTemePosLag()[0][0]) {
                updateLagData = true;
                oldLagX = currentSat.getTemePosLag()[0][0];
            }

            // update Lead data if needed
            if (updateLeadData) {
                double[][] leadData = AER.calculate(currentGs.getLla_deg_m(), currentSat.getTemePosLead(),
                        currentSat.getTimeLead());
                polarPlotLbl.setAerLead(leadData);
                futurePasses = GroundPass.find(currentGs, currentSat);
                // System.out.println("Lead updated");
            }

            // update lag data if needed
            if (updateLagData) {
                polarPlotLbl.setAerLag(AER.calculate(currentGs.getLla_deg_m(), currentSat.getTemePosLag(),
                        currentSat.getTimeLag()));
                // System.out.println("Lag updated");
            }

            // Figure out when the next pass is
            if (currentPass != null) // There's a pass, but it ended
                if (Time.dateTimeOfJd(currentPass.setTime()).isBefore(currentTime)) {
                    currentPass = null;
                    nextPassLbl.setText("");
                }
            // There's no pass now, but we can predict the next one
            if (futurePasses.size() > 0 && currentPass == null) {
                DateTime nextRise = Time.dateTimeOfJd(futurePasses.get(0).riseTime());
                if (nextRise.isAfter(currentTime)) {
                    nextPassLbl.setText(NEXT_PASS_LBL_TXT + nextRise.toString("MMM dd, YYYY -- HH:mm:ss"));
                } else {// It just started
                    currentPass = futurePasses.remove(0);
                    nextPassLbl
                            .setText("Pass ends at: " + new DateTime(Time.dateTimeOfJd(currentPass.setTime()))
                                    .toString("MMM dd, YYYY -- HH:mm:ss"));
                }
            }
        } // lead / lag data shown

        // Track a satellite
        if (trackButton.isSelected()) {
            try {
                trackSatellite((int) Math.round(aer[0]), (int) Math.round(aer[1]), aer[2]);
            } catch (Failure f) { // TODO Display failure
                String stackTrace = "";
                for (StackTraceElement ste : f.getStackTrace())
                    stackTrace += ste.toString();
                JOptionPane.showMessageDialog(this, "Error: " + f.getMessage() + "\n" + stackTrace, "Error",
                        JOptionPane.ERROR_MESSAGE);
                trackButton.setSelected(false);
            }
        }

        // TODO Adjust for Doppler here
        // put in new range and time
        // adjust TS2000 settings accordingly

    } else { // NAN check
        currInfoLbl.setText(CURRENT_TRACKING_INFORMATION + "Satellite Ephemeris Not Available");
        clearCurrTrackInfo();

        polarPlotLbl.setTimeString(timeAsString);
        polarPlotLbl.setGs2SatNameString(
                String.format("%s to %s", currentGs.getStationName().trim(), currentSat.getName().trim()));

        polarPlotLbl.clearLeadLagData(); // clear lead/lag data
        polarPlotLbl.resetCurrentPosition(); // clear current point?
    }

    polarPlotLbl.repaint();

}