Example usage for org.joda.time.format ISODateTimeFormat dateTime

List of usage examples for org.joda.time.format ISODateTimeFormat dateTime

Introduction

In this page you can find the example usage for org.joda.time.format ISODateTimeFormat dateTime.

Prototype

public static DateTimeFormatter dateTime() 

Source Link

Document

Returns a formatter that combines a full date and time, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ss.SSSZZ).

Usage

From source file:org.slc.sli.bulk.extract.files.metadata.ManifestFile.java

License:Apache License

/**
 * Change the timestamp into our own format.
 * @param date//from ww w. java2 s .c  o  m
 *      Timestamp
 * @return
 *      returns the formatted timestamp
 */
public static String getTimeStamp(DateTime date) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String timeStamp = fmt.print(date);
    return timeStamp;
}

From source file:org.sonar.server.es.EsUtils.java

License:Open Source License

@CheckForNull
public static Date parseDateTime(@Nullable String s) {
    if (s == null) {
        return null;
    }/*from  w w  w .  jav  a 2s  .  c  om*/
    return ISODateTimeFormat.dateTime().parseDateTime(s).toDate();
}

From source file:org.sonar.server.es.EsUtils.java

License:Open Source License

@CheckForNull
public static String formatDateTime(@Nullable Date date) {
    if (date != null) {
        return ISODateTimeFormat.dateTime().print(date.getTime());
    }//  w ww. j ava2s. c  o  m
    return null;
}

From source file:org.sonar.server.search.IndexUtils.java

License:Open Source License

public static String format(Date date) {
    return ISODateTimeFormat.dateTime().print(date.getTime());
}

From source file:org.spf4j.perf.tsdb.TimeSeriesDatabase.java

License:Open Source License

public void writeCsvTable(final String tableName, final File output) throws IOException {
    TSTable table = getTSTable(tableName);
    TimeSeries data = readAll(tableName);
    DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
    try (Writer writer = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(output), Charsets.UTF_8))) {
        Csv.writeCsvElement("timestamp", writer);
        for (String colName : table.getColumnNames()) {
            writer.append(',');
            Csv.writeCsvElement(colName, writer);
        }/*from  ww  w.j a v a2s.co  m*/
        writer.write('\n');
        long[] timestamps = data.getTimeStamps();
        long[][] values = data.getValues();
        for (int i = 0; i < timestamps.length; i++) {
            Csv.writeCsvElement(formatter.print(timestamps[i]), writer);
            for (long val : values[i]) {
                writer.append(',');
                Csv.writeCsvElement(Long.toString(val), writer);
            }
            writer.write('\n');
        }
    }
}

From source file:org.spf4j.perf.tsdb.TimeSeriesDatabase.java

License:Open Source License

public void writeCsvTables(final List<String> tableNames, final File output) throws IOException {
    DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
    try (Writer writer = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(output), Charsets.UTF_8))) {
        String firstTable = tableNames.get(0);
        TSTable table = getTSTable(firstTable);
        Csv.writeCsvElement("table", writer);
        writer.append(',');
        Csv.writeCsvElement("timestamp", writer);
        for (String colName : table.getColumnNames()) {
            writer.append(',');
            Csv.writeCsvElement(colName, writer);
        }/*from   ww w  .java2s .  c om*/
        writer.write('\n');

        for (String tableName : tableNames) {
            TimeSeries data = readAll(tableName);
            long[] timestamps = data.getTimeStamps();
            long[][] values = data.getValues();
            for (int i = 0; i < timestamps.length; i++) {
                Csv.writeCsvElement(tableName, writer);
                writer.append(',');
                Csv.writeCsvElement(formatter.print(timestamps[i]), writer);
                for (long val : values[i]) {
                    writer.append(',');
                    Csv.writeCsvElement(Long.toString(val), writer);
                }
                writer.write('\n');
            }
        }
    }
}

From source file:org.springframework.format.datetime.joda.DateTimeFormatterFactory.java

License:Apache License

/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter//from   ww w .  j a  v a2  s  .co m
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
    DateTimeFormatter dateTimeFormatter = null;
    if (StringUtils.hasLength(this.pattern)) {
        dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
    } else if (this.iso != null && this.iso != ISO.NONE) {
        switch (this.iso) {
        case DATE:
            dateTimeFormatter = ISODateTimeFormat.date();
            break;
        case TIME:
            dateTimeFormatter = ISODateTimeFormat.time();
            break;
        case DATE_TIME:
            dateTimeFormatter = ISODateTimeFormat.dateTime();
            break;
        case NONE:
            /* no-op */
            break;
        default:
            throw new IllegalStateException("Unsupported ISO format: " + this.iso);
        }
    } else if (StringUtils.hasLength(this.style)) {
        dateTimeFormatter = DateTimeFormat.forStyle(this.style);
    }

    if (dateTimeFormatter != null && this.timeZone != null) {
        dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
    }
    return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}

From source file:org.springframework.format.datetime.joda.JodaTimeFormattingConfigurer.java

License:Apache License

private DateTimeFormatter getJodaDateTimeFormatter() {
    if (this.useIsoFormat) {
        return ISODateTimeFormat.dateTime();
    }// w w  w .  ja va2  s .  c  om
    if (this.dateTimeStyle != null) {
        return DateTimeFormat.forStyle(this.dateTimeStyle);
    } else {
        return DateTimeFormat.shortDateTime();
    }
}

From source file:org.sweble.wom3.impl.Toolbox.java

License:Open Source License

public static String dateTimeToString(DateTime datetime) {
    DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
    return datetime.toString(formatter);
}

From source file:org.traccar.database.StatisticsManager.java

License:Apache License

private void checkSplit() {
    int currentUpdate = Calendar.getInstance().get(SPLIT_MODE);
    if (lastUpdate.getAndSet(currentUpdate) != currentUpdate) {
        Statistics statistics = new Statistics();
        statistics.setCaptureTime(new Date());
        statistics.setActiveUsers(users.size());
        statistics.setActiveDevices(devices.size());
        statistics.setRequests(requests);
        statistics.setMessagesReceived(messagesReceived);
        statistics.setMessagesStored(messagesStored);
        statistics.setMailSent(mailSent);
        statistics.setSmsSent(smsSent);//from  www  .  j  av a 2 s.  com
        statistics.setGeocoderRequests(geocoderRequests);
        statistics.setGeolocationRequests(geolocationRequests);

        try {
            Context.getDataManager().addObject(statistics);
        } catch (SQLException e) {
            Log.warning(e);
        }

        String url = Context.getConfig().getString("server.statistics");
        if (url != null) {
            String time = ISODateTimeFormat.dateTime().print(statistics.getCaptureTime().getTime());
            Request request = new RequestBuilder("POST").setUrl(url)
                    .addHeader("Content-Type", "application/x-www-form-urlencoded")
                    .addFormParam("version", Log.getAppVersion()).addFormParam("captureTime", time)
                    .addFormParam("activeUsers", String.valueOf(statistics.getActiveUsers()))
                    .addFormParam("activeDevices", String.valueOf(statistics.getActiveDevices()))
                    .addFormParam("requests", String.valueOf(statistics.getRequests()))
                    .addFormParam("messagesReceived", String.valueOf(statistics.getMessagesReceived()))
                    .addFormParam("messagesStored", String.valueOf(statistics.getMessagesStored()))
                    .addFormParam("mailSent", String.valueOf(statistics.getMailSent()))
                    .addFormParam("smsSent", String.valueOf(statistics.getSmsSent()))
                    .addFormParam("geocoderRequests", String.valueOf(statistics.getGeocoderRequests()))
                    .addFormParam("geolocationRequests", String.valueOf(statistics.getGeolocationRequests()))
                    .build();
            Context.getAsyncHttpClient().prepareRequest(request).execute();
        }

        users.clear();
        devices.clear();
        requests = 0;
        messagesReceived = 0;
        messagesStored = 0;
        mailSent = 0;
        smsSent = 0;
        geocoderRequests = 0;
        geolocationRequests = 0;
    }
}