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:editors.DateTimeEditor.java

@Override
public String getAsText() {
    DateTime dateTime = (DateTime) getValue();
    if (dateTime == null) {
        return null;
    } else {//from   w  ww. j a va 2 s .  c  o m
        return dateTime.toString(DATE_FORMAT);
    }
}

From source file:edu.internet2.middleware.shibboleth.idp.StatusServlet.java

License:Open Source License

/**
 * Prints out information about the operating environment. This includes the operating system name, version and
 * architecture, the JDK version, available CPU cores, memory currently used by the JVM process, the maximum amount
 * of memory that may be used by the JVM, and the current time in UTC.
 * /*from w  w w.  j a  v  a2 s. c  o m*/
 * @param out output writer to which information will be written
 */
protected void printOperatingEnvironmentInformation(PrintWriter out) {
    Runtime runtime = Runtime.getRuntime();
    DateTime now = new DateTime(ISOChronology.getInstanceUTC());

    out.println("### Operating Environment Information");
    out.println("operating_system: " + System.getProperty("os.name"));
    out.println("operating_system_version: " + System.getProperty("os.version"));
    out.println("operating_system_architecture: " + System.getProperty("os.arch"));
    out.println("jdk_version: " + System.getProperty("java.version"));
    out.println("available_cores: " + runtime.availableProcessors());
    out.println("used_memory: " + runtime.totalMemory() / 1048576 + "MB");
    out.println("maximum_memory: " + runtime.maxMemory() / 1048576 + "MB");
    out.println("start_time: " + startTime.toString(dateFormat));
    out.println("current_time: " + now.toString(dateFormat));
    out.println("uptime: " + (now.getMillis() - startTime.getMillis()) + "ms");
}

From source file:edu.uta.courses.service.impl.EventServiceImpl.java

@Override
public String[] convertDateToString(DateTime time) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MM yyyy kk mm");
    String date = time.toString(formatter);
    String[] list = date.split(" ");

    return list;/*from www. java 2 s.  com*/
}

From source file:edu.wpi.cs.wpisuitetng.modules.cal.ui.navigation.MiniCalendarPanel.java

License:Open Source License

public void display(DateTime date) {
    //Title Bar Pane
    monthName = new JLabel(date.toString(Months.monthLblFormat), JLabel.CENTER);
    monthName.setFont(new Font("DejaVu Sans", Font.BOLD, 12));
    monthName.setMaximumSize(new Dimension(4400, 30));
    this.removeAll();
    this.setLayout(new BorderLayout());

    JPanel titlePane = new JPanel();
    JButton nextButton = new JButton(">");
    JButton prevButton = new JButton("<");

    titlePane.setLayout(new BoxLayout(titlePane, BoxLayout.X_AXIS));

    titlePane.add(prevButton);// w  ww .  j  av  a 2s.c  o m
    titlePane.add(nextButton);

    prevButton.setFocusable(false);
    prevButton.setBackground(UIManager.getDefaults().getColor("Panel.background"));
    nextButton.setFocusable(false);
    nextButton.setBackground(UIManager.getDefaults().getColor("Panel.background"));

    prevButton.setBorder(new EmptyBorder(5, 5, 5, 5));
    nextButton.setBorder(new EmptyBorder(5, 5, 5, 5));

    titlePane.add(monthName);

    calendarPreloader = new CalendarNavigationModule(date, mainPanel, monthOnly);
    this.miniCalendar = this.calendarPreloader.renderComponent();

    this.add(miniCalendar, BorderLayout.CENTER);
    this.add(titlePane, BorderLayout.NORTH);

    //add event listeners
    nextButton.addActionListener(nextListener);
    prevButton.addActionListener(prevListener);

    currentDate = date;

    this.revalidate();
    this.repaint();
}

From source file:energy.usef.agr.workflow.nonudi.service.PowerMatcher.java

License:Apache License

/**
 * Returns a interval ({@link String}) based on the date, ptuIndex, ptuDuration and number of ptus. For example:
 * "2015-05-01T13:00:00Z/2015-05-01T14:00:00Z". This time format is compatible with the PowerMatcher.
 *
 * @param date//from  w  w w.ja v  a  2 s. c  o  m
 * @param ptuIndex
 * @param ptuDuration
 * @param numberOfPtus
 * @return
 */
public static String getInterval(LocalDate date, int ptuIndex, int ptuDuration, int numberOfPtus) {
    LocalDateTime start = date.toDateTimeAtStartOfDay().toLocalDateTime()
            .plusMinutes((ptuIndex - 1) * ptuDuration);
    LocalDateTime end = start.plusMinutes(numberOfPtus * ptuDuration).minusSeconds(1);

    DateTime startDateTime = start.toDateTime().toDateTime(DateTimeZone.UTC);
    DateTime endDateTime = end.toDateTime().toDateTime(DateTimeZone.UTC);
    return startDateTime.toString(POWER_MATCHER_TIME_FORMAT) + "/"
            + endDateTime.toString(POWER_MATCHER_TIME_FORMAT);
}

From source file:es.usc.citius.servando.calendula.util.ScheduleHelper.java

License:Open Source License

public static boolean cycleEnabledForDate(LocalDate date, LocalDate s, int activeDays, int restDays) {
    DateTime start = s.toDateTimeAtStartOfDay();
    DateTime day = date.toDateTimeAtStartOfDay().plusDays(1);

    if (day.isBefore(start))
        return false;

    int activePeriod = activeDays;
    int restPeriod = restDays;
    int cycleLength = activePeriod + restPeriod;
    int days = (int) new Interval(start, day).toDuration().getStandardDays();
    int cyclesUntilNow = days / cycleLength;

    Log.d("ScheduleHelper", "start: " + start.toString("dd/MM/YYYY") + ", day: " + day.toString("dd/MM/YYYY"));
    Log.d("ScheduleHelper", "Active: " + activePeriod + ", rest: " + restPeriod + ", cycle: " + cycleLength
            + ", days: " + days + ", cyclesUntilNow: " + cyclesUntilNow);

    // get start of current cycle

    DateTime cycleStart = start.plusDays(cyclesUntilNow * cycleLength);

    return new Interval(cycleStart, cycleStart.plusDays(activePeriod)).contains(date.toDateTimeAtStartOfDay());

}

From source file:eu.cloudwave.wp5.common.util.DateTimes.java

License:Apache License

/**
 * Returns the given {@link DateTime} formatted according to the given pattern.
 * //from w  w w  . j  a v a  2s .c  o  m
 * @param dateTime
 *          the {@link DateTime}
 * @param pattern
 *          the formatting pattern
 * @return the formatted {@link DateTime} as {@link String}
 */
public static String format(final DateTime dateTime, final String pattern) {
    final DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern);
    return dateTime.toString(formatter);
}

From source file:eu.hydrologis.jgrass.geonotes.fieldbook.actions.ExportToFeatureLayerAction.java

License:Open Source License

public void run() {

    IRunnableWithProgress operation = new IRunnableWithProgress() {

        public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException {
            List<GeonotesHandler> currentGeonotesSelection = geonotesViewer.getCurrentGeonotesSelection();
            if (currentGeonotesSelection == null || currentGeonotesSelection.size() == 0) {
                currentGeonotesSelection = (List<GeonotesHandler>) geonotesViewer.getInput();
            }/*from   w  w w .  j a  v  a2 s .c o  m*/

            DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm"); //$NON-NLS-1$
            GeometryFactory gF = new GeometryFactory();
            CoordinateReferenceSystem mapCrs = ApplicationGIS.getActiveMap().getViewportModel().getCRS();

            SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
            b.setName("geonotes"); //$NON-NLS-1$
            b.setCRS(mapCrs);
            b.add("the_geom", Point.class); //$NON-NLS-1$

            b.add("title", String.class); //$NON-NLS-1$
            b.add("text", String.class); //$NON-NLS-1$
            b.add("timestamp", String.class); //$NON-NLS-1$

            SimpleFeatureType featureType = b.buildFeatureType();

            try {
                pm.beginTask(Messages.getString("ExportToFeatureLayerAction__exporting_geonotes"), //$NON-NLS-1$
                        currentGeonotesSelection.size());
                newCollection = FeatureCollections.newCollection();
                for (int i = 0; i < currentGeonotesSelection.size(); i++) {

                    GeonotesHandler geonotesHandler = currentGeonotesSelection.get(i);
                    Coordinate position = geonotesHandler.getPosition();
                    DateTime creationDate = geonotesHandler.getCreationDate();
                    GeonotesTextareaTable geonotesTextareaTable = geonotesHandler.getGeonotesTextareaTable();
                    String text = ""; //$NON-NLS-1$
                    if (geonotesTextareaTable != null) {
                        text = geonotesTextareaTable.getText();
                    }
                    String title = geonotesHandler.getTitle();

                    CoordinateReferenceSystem noteCrs = geonotesHandler.getCrs();
                    MathTransform transform = CRS.findMathTransform(noteCrs, mapCrs);

                    Point point = gF.createPoint(position);
                    Geometry reprojectPoint = JTS.transform(point, transform);

                    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
                    Object[] values = new Object[] { reprojectPoint, title, text,
                            creationDate.toString(dateTimeFormatter) };
                    builder.addAll(values);
                    SimpleFeature feature = builder.buildFeature(featureType.getTypeName() + "." + i); //$NON-NLS-1$
                    newCollection.add(feature);
                    pm.worked(1);
                }
                pm.done();

            } catch (Exception e1) {
                String message = Messages.getString("ExportToFeatureLayerAction__error_while_exporting"); //$NON-NLS-1$
                ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, GeonotesPlugin.PLUGIN_ID, e1);
                e1.printStackTrace();
            }

        }
    };
    PlatformGIS.runInProgressDialog(EXPORT_TO_SHAPEFILE, true, operation, false);
    try {
        FeatureUtilities.featureCollectionToTempLayer(newCollection);
    } catch (Exception e) {
        MessageDialog.openError(geonotesViewer.getTable().getShell(),
                Messages.getString("ExportToFeatureLayerAction__error"), //$NON-NLS-1$
                Messages.getString("ExportToFeatureLayerAction__error_while_creating_layer")); //$NON-NLS-1$
    }
}

From source file:eu.hydrologis.jgrass.geonotes.GeonotesHandler.java

License:Open Source License

/**
 * Constructs a new Geonote, making it immediatly persistent to database.
 * //from www .j  a va  2  s .  c om
 * @param east easting coordinate in {@link DefaultGeographicCRS#WGS84}.
 * @param north northing coordinate in {@link DefaultGeographicCRS#WGS84}.
 * @param title a short title for the geonote or <code>null</code>.
 * @param info an information text or <code>null</code>.
 * @param type an id for the note type. Can currently be one of:
 *                  <br><ul>
 *                          <li>{@link #NORMAL} </li>
 *                          <li>{@link #GPS} </li>
 *                          <li>{@link #PHOTO} </li>
 *                      </ul>
 * @param creationTime the {@link DateTime} of creation of the geonote.
 * @param azimut the azimut value if the geonote has directionality or <code>null</code>.
 * @param color a color for the note in format r:g:b:a integers or <code>null</code>.
 * @param width a width for the geonote or <code>null</code>.
 * @param height a height for the geonote or <code>null</code>.
 * @throws Exception
 */
public GeonotesHandler(Double east, Double north, String title, String info, Integer type,
        DateTime creationTime, Double azimut, String color, Integer width, Integer height) throws Exception {
    if (east == null) {
        throw new IllegalArgumentException("The east coordinate is a mandatory parameter to create a geonote.");
    }
    if (north == null) {
        throw new IllegalArgumentException("The west coordinate is a mandatory parameter to create a geonote.");
    }
    if (creationTime == null) {
        throw new IllegalArgumentException("The creationtime is a mandatory parameter to create a geonote.");
    }
    if (title == null) {
        title = DEFAULT_GEONOTE_TITLE;
    }
    if (info == null) {
        String dateString = creationTime.toString(BeegisUtilsPlugin.dateTimeFormatterYYYYMMDDHHMM);
        info = "Date:" + dateString + "\nN:" + north + "\nE:" + east;
    }
    if (type == null) {
        type = DEFAULT_GEONOTE_TYPE;
    }
    if (width == null) {
        width = DEFAULT_GEONOTE_WIDTH;
    }
    if (height == null) {
        height = DEFAULT_GEONOTE_HEIGHT;
    }
    if (color == null) {
        color = DEFAULTBACKGROUNDCOLORS[0][0] + ":" + DEFAULTBACKGROUNDCOLORS[0][1] + ":"
                + DEFAULTBACKGROUNDCOLORS[0][2] + ":255";
    }

    Session session = openSession();
    try {
        Transaction transaction = session.beginTransaction();
        geonoteTable = new GeonotesTable();
        geonoteTable.setEast(east);
        geonoteTable.setNorth(north);
        geonoteTable.setType(type);
        geonoteTable.setTitle(title);
        geonoteTable.setInfo(info);
        geonoteTable.setCreationDateTime(creationTime);
        geonoteTable.setColor(color);
        geonoteTable.setWidth(width);
        geonoteTable.setHeight(height);
        if (azimut != null) {
            geonoteTable.setAzimut(azimut);
        }
        id = (Long) session.save(geonoteTable);
        geonoteTable.setTitle(geonoteTable.getTitle() + " - " + id);
        session.update(geonoteTable);
        transaction.commit();
    } finally {
        session.close();
    }
}

From source file:eu.hydrologis.jgrass.geonotes.GeonotesHandler.java

License:Open Source License

/**
 * Dump the contents of a geonote to disk.
 * //from  w w w  .j  a  va 2 s.co  m
 * @param folderPath the folder into which dump the geonotes data structure.
 * @param drawAreaImage 
 * @throws Exception
 */
public void dumpNote(final String folderPath, final Image drawAreaImage) throws Exception {

    IRunnableWithProgress operation = new IRunnableWithProgress() {

        public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException {

            try {
                pm.beginTask("Dump geonote to disk.", 2);
                File folderFile = new File(folderPath);
                if (!folderFile.exists()) {
                    throw new InterruptedException("The supplied folder " + folderPath
                            + " doesn't exist. Can't dump the geonote into it.");
                }

                String title = geonoteTable.getTitle();
                title = title.replace(' ', '_');
                File mainDir = new File(folderFile.getAbsolutePath() + File.separator + title);
                if (!mainDir.exists() && !mainDir.mkdir()) {
                    throw new InterruptedException("Coudn't create folder: " + mainDir.getAbsolutePath());
                }

                // dump info text
                try {
                    File textFile = new File(mainDir.getAbsolutePath() + File.separator + "geonote_info.txt");
                    BufferedWriter bW = new BufferedWriter(new FileWriter(textFile));

                    StringBuilder msgBuilder = new StringBuilder();
                    msgBuilder.append("Geonote id: ");
                    msgBuilder.append(id);
                    msgBuilder.append("\n\n");
                    msgBuilder.append("Geonote title: ");
                    msgBuilder.append(title);
                    msgBuilder.append("\n\n");
                    msgBuilder.append("Geonote color: ");
                    String colorString = getColorString();
                    msgBuilder.append("r:g:b:a = ");
                    msgBuilder.append(colorString);
                    msgBuilder.append("\n\n");
                    msgBuilder.append("Geonote type: ");
                    msgBuilder.append(getType());
                    msgBuilder.append("\n\n");
                    msgBuilder.append("Creation date: ");
                    DateTime creationDateTime = geonoteTable.getCreationDateTime();
                    msgBuilder
                            .append(creationDateTime.toString(BeegisUtilsPlugin.dateTimeFormatterYYYYMMDDHHMM));
                    msgBuilder.append("\n\n");
                    msgBuilder.append("Position (WGS 84 lat/long): ");
                    Coordinate position = new Coordinate(geonoteTable.getEast(), geonoteTable.getNorth());
                    msgBuilder.append(position.x);
                    msgBuilder.append(" / ");
                    msgBuilder.append(position.y);
                    msgBuilder.append("\n\n");

                    IMap activeMap = ApplicationGIS.getActiveMap();
                    if (activeMap != null) {
                        CoordinateReferenceSystem mapCrs = activeMap.getViewportModel().getCRS();
                        String crsName = mapCrs.getName().toString();
                        msgBuilder.append("Position (" + crsName + "): ");
                        MathTransform mathTransform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mapCrs,
                                true);
                        Coordinate newPosition = JTS.transform(position, null, mathTransform);
                        msgBuilder.append(newPosition.x);
                        msgBuilder.append(" / ");
                        msgBuilder.append(newPosition.y);
                        msgBuilder.append("\n\n");
                    }
                    bW.write(msgBuilder.toString());
                    bW.close();
                    pm.worked(1);
                } catch (Exception e) {
                    e.printStackTrace();
                    GeonotesPlugin.log("GeonotesPlugin problem: eu.hydrologis.jgrass.geonotes##run", e); //$NON-NLS-1$
                }

                // dump text
                try {
                    File textFile = new File(
                            mainDir.getAbsolutePath() + File.separator + "geonote_textbox.txt");
                    BufferedWriter bW = new BufferedWriter(new FileWriter(textFile));
                    GeonotesTextareaTable textareaTable = getGeonotesTextareaTable();
                    String text = "";
                    if (textareaTable != null) {
                        String tmptext = textareaTable.getText();
                        if (text != null) {
                            text = tmptext;
                        }
                    }
                    bW.write(text);
                    bW.close();
                    pm.worked(1);
                } catch (Exception e) {
                    e.printStackTrace();
                    GeonotesPlugin.log("GeonotesPlugin problem: eu.hydrologis.jgrass.geonotes##run", e); //$NON-NLS-1$
                }

                try {
                    // dump image
                    File imageFile = new File(
                            mainDir.getAbsolutePath() + File.separator + "geonote_paintbox.png");
                    if (drawAreaImage != null) {
                        OutputStream out = new FileOutputStream(imageFile);
                        ImageLoader imageLoader = new ImageLoader();
                        imageLoader.data = new ImageData[] { drawAreaImage.getImageData() };
                        imageLoader.save(out, SWT.IMAGE_PNG);
                        out.close();
                    }

                    pm.worked(1);
                } catch (Exception e) {
                    e.printStackTrace();
                    GeonotesPlugin.log("GeonotesPlugin problem: eu.hydrologis.jgrass.geonotes##run", e); //$NON-NLS-1$
                }
                pm.done();

                // dump media box
                File mediaDir = new File(mainDir.getAbsolutePath() + File.separator + "geonote_mediabox");
                if (!mediaDir.exists() && !mediaDir.mkdir()) {
                    throw new InterruptedException("Coudn't create folder: " + mediaDir.getAbsolutePath());
                }

                List<GeonotesMediaboxTable> mediaboxTables = getGeonotesMediaboxTables(null);
                pm.beginTask("Dump media box to disk.", mediaboxTables.size());
                for (GeonotesMediaboxTable mediaboxTable : mediaboxTables) {
                    GeonotesMediaboxBlobsTable mediaboxBlobsTable = getGeonotesMediaboxBlobsTable(
                            mediaboxTable);
                    String mediaName = mediaboxTable.getMediaName();

                    File file = new File(mediaDir, mediaName);
                    mediaboxBlobsTable.getFromMediaboxToFile(file);

                    pm.worked(1);
                }
                pm.done();
            } catch (Exception e) {
                GeonotesPlugin.log("GeonotesPlugin problem: eu.hydrologis.jgrass.geonotes##run", e); //$NON-NLS-1$
                e.printStackTrace();
                throw new InterruptedException(e.getLocalizedMessage());
            }

        }

    };

    PlatformGIS.runInProgressDialog("Dump geonote", true, operation, true);

}