Example usage for java.text DateFormat getTimeZone

List of usage examples for java.text DateFormat getTimeZone

Introduction

In this page you can find the example usage for java.text DateFormat getTimeZone.

Prototype

public TimeZone getTimeZone() 

Source Link

Document

Gets the time zone.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DateFormat dateFormat = DateFormat.getDateTimeInstance();

    String s = dateFormat.format(new Date());
    System.out.println(dateFormat.getTimeZone());

}

From source file:Util.java

public static long getLocalEpoch(TimeZone timezone) {
    DateFormat dateFormat = DateFormat.getInstance();
    if (timezone != null)
        dateFormat.setTimeZone(timezone);
    long result = 0;
    try {/* ww w  . j av a  2 s  .c  o  m*/
        result = DateFormat.getInstance().parse("01/02/70 12:00 AM").getTime();
    } catch (ParseException e) {

    }

    if (dateFormat.getTimeZone().inDaylightTime(new Date())) {
        result -= 60 * 60 * 1000;
    }
    return result;
}

From source file:org.kalypso.ogc.sensor.tableview.swing.tablemodel.ObservationTableModel.java

/**
 * Exports the contents of the model//from  w w w . j  av a 2s  .co m
 */
public void dump(final String separator, final BufferedWriter writer) throws IOException {
    if (m_sharedModel.isEmpty())
        return;

    final Object checkObject = m_sharedModel.first();

    // will be used for formating the various columns
    final Format[] nf = new Format[m_columns.size() + 1];

    // find appropriate format for shared column (Attention: can still be null)
    if (checkObject instanceof Date)
        nf[0] = TimeseriesUtils.getDateFormat();
    else if (checkObject instanceof Integer)
        nf[0] = NumberFormat.getIntegerInstance();
    else if (checkObject instanceof Number)
        nf[0] = NumberFormat.getNumberInstance();

    // dump header and fetch numberformats
    writer.write(m_sharedAxis.getName());
    if (nf[0] instanceof DateFormat) {
        final DateFormat df = (DateFormat) nf[0];
        final TimeZone timeZone = df.getTimeZone();
        if (timeZone != null) {
            writer.write(" ("); //$NON-NLS-1$
            writer.write(timeZone.getID());
            writer.write(")"); //$NON-NLS-1$
        }
    }

    int col = 1;
    for (final Object element : m_columns) {
        final TableViewColumn tvc = (TableViewColumn) element;

        nf[col] = TimeseriesUtils.getNumberFormat(tvc.getFormat());

        writer.write(separator);
        writer.write(tvc.getName());

        col++;
    }

    writer.newLine();

    // dump values
    int row = 0;
    for (final Object key : m_sharedModel) {
        writer.write(nf[0] == null ? key.toString() : nf[0].format(key));

        col = 1;
        for (; col < getColumnCount(); col++) {
            final Object value = getValueAt(row, col);

            writer.write(separator);

            if (nf[col] != null && value != null)
                writer.write(nf[col].format(value));
            else
                writer.write(""); //$NON-NLS-1$
        }

        writer.newLine();
        row++;
    }
}