Search in sources :

Example 46 with DateFormat

use of java.text.DateFormat in project neo4j by neo4j.

the class TransactionThroughputChecker method newDateFormat.

private static DateFormat newDateFormat() {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
    TimeZone timeZone = TimeZone.getTimeZone("UTC");
    format.setTimeZone(timeZone);
    return format;
}
Also used : TimeZone(java.util.TimeZone) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 47 with DateFormat

use of java.text.DateFormat in project zipkin by openzipkin.

the class UtilTest method midnightUTCTest.

@Test
public void midnightUTCTest() throws ParseException {
    DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
    iso8601.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = iso8601.parse("2011-04-15T20:08:18Z");
    long midnight = midnightUTC(date.getTime());
    assertThat(iso8601.format(new Date(midnight))).isEqualTo("2011-04-15T00:00:00Z");
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 48 with DateFormat

use of java.text.DateFormat in project sensorreadout by onyxbits.

the class TimeChart method getDateFormat.

/**
   * Returns the date format pattern to be used, based on the date range.
   * 
   * @param start the start date in milliseconds
   * @param end the end date in milliseconds
   * @return the date format
   */
private DateFormat getDateFormat(double start, double end) {
    if (mDateFormat != null) {
        SimpleDateFormat format = null;
        try {
            format = new SimpleDateFormat(mDateFormat);
            return format;
        } catch (Exception e) {
        // do nothing here
        }
    }
    DateFormat format = SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM);
    double diff = end - start;
    if (diff > DAY && diff < 5 * DAY) {
        format = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
    } else if (diff < DAY) {
        format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM);
    }
    return format;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 49 with DateFormat

use of java.text.DateFormat in project openhab1-addons by openhab.

the class EBusTelegramCSVWriter method writeTelegram.

/**
     * Writes a eBUS telegram to the CSV file
     * 
     * @param telegram
     * @param comment
     * @throws IOException
     */
public synchronized void writeTelegram(EBusTelegram telegram, String comment) {
    try {
        if (writer == null) {
            return;
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        writer.write(df.format(date));
        writer.write(";");
        writer.write('"' + EBusUtils.toHexDumpString(telegram.getType()) + '"');
        writer.write(";");
        writer.write('"' + EBusUtils.toHexDumpString(telegram.getSource()) + '"');
        writer.write(";");
        writer.write('"' + EBusUtils.toHexDumpString(telegram.getDestination()) + '"');
        writer.write(";");
        short u = telegram.getCommand();
        byte x = (byte) u;
        byte y = (byte) (u >> 8);
        writer.write(EBusUtils.toHexDumpString(y));
        writer.write(" ");
        writer.write(EBusUtils.toHexDumpString(x));
        writer.write(";");
        writer.write('"' + EBusUtils.toHexDumpString((byte) telegram.getDataLen()) + '"');
        writer.write(";");
        writer.write(EBusUtils.toHexDumpString(telegram.getData()).toString());
        writer.write(";");
        writer.write('"' + EBusUtils.toHexDumpString(telegram.getCRC()) + '"');
        writer.write(";");
        if (telegram.getType() != EBusTelegram.TYPE_MASTER_SLAVE) {
            writer.write(";");
            writer.write(";");
            writer.write(";");
            writer.write(";");
        } else {
            writer.write('"' + "00" + '"');
            writer.write(";");
            writer.write('"' + EBusUtils.toHexDumpString((byte) telegram.getSlaveDataLen()) + '"');
            writer.write(";");
            writer.write(EBusUtils.toHexDumpString(telegram.getSlaveData()).toString());
            writer.write(";");
            writer.write('"' + EBusUtils.toHexDumpString((byte) telegram.getSlaveCRC()) + '"');
            writer.write(";");
        }
        writer.write(comment);
        writer.newLine();
        writer.flush();
    } catch (IOException e) {
        logger.error("error", e);
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 50 with DateFormat

use of java.text.DateFormat in project jodd by oblac.

the class CalendarConverterTest method testCalendarDate.

@Test
public void testCalendarDate() {
    JDateTime jdt = new JDateTime();
    CalendarConverter calendarConverter = new CalendarConverter();
    Calendar gc = calendarConverter.convert(jdt);
    DateFormat df = new SimpleDateFormat();
    assertEquals(df.format(gc.getTime()), df.format(Convert.toDate(jdt)));
}
Also used : CalendarConverter(jodd.typeconverter.impl.CalendarConverter) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) JDateTime(jodd.datetime.JDateTime) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

DateFormat (java.text.DateFormat)646 SimpleDateFormat (java.text.SimpleDateFormat)486 Date (java.util.Date)315 ParseException (java.text.ParseException)132 Calendar (java.util.Calendar)78 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)48 IOException (java.io.IOException)43 File (java.io.File)31 HashMap (java.util.HashMap)27 GregorianCalendar (java.util.GregorianCalendar)24 TimeZone (java.util.TimeZone)23 Locale (java.util.Locale)18 Timestamp (java.sql.Timestamp)17 List (java.util.List)14 InputStream (java.io.InputStream)12 DateTime (org.joda.time.DateTime)11 Map (java.util.Map)10 Matcher (java.util.regex.Matcher)8 TestBean (org.springframework.tests.sample.beans.TestBean)8