Example usage for java.util TimeZone setDefault

List of usage examples for java.util TimeZone setDefault

Introduction

In this page you can find the example usage for java.util TimeZone setDefault.

Prototype

public static void setDefault(TimeZone zone) 

Source Link

Document

Sets the TimeZone that is returned by the getDefault method.

Usage

From source file:Main.java

public static void setTime(Activity activity, TextView view, long millis) {
    int flags = DateUtils.FORMAT_SHOW_TIME;
    flags |= DateUtils.FORMAT_CAP_NOON_MIDNIGHT;
    if (DateFormat.is24HourFormat(activity)) {
        flags |= DateUtils.FORMAT_24HOUR;
    }// ww w.ja  v a2s  . c o  m

    // Unfortunately, DateUtils doesn't support a timezone other than the
    // default timezone provided by the system, so we have this ugly hack
    // here to trick it into formatting our time correctly. In order to
    // prevent all sorts of craziness, we synchronize on the TimeZone class
    // to prevent other threads from reading an incorrect timezone from
    // calls to TimeZone#getDefault()
    // TODO fix this if/when DateUtils allows for passing in a timezone
    String timeString;
    synchronized (TimeZone.class) {
        timeString = DateUtils.formatDateTime(activity, millis, flags);
        TimeZone.setDefault(null);
    }

    view.setTag(millis);
    view.setText(timeString);
}

From source file:org.geoserver.kml.KMLTest.java

@BeforeClass
public static void setTimeZone() {
    // System.setProperty("user.timezone", "UTC");
    oldTimeZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}

From source file:jenkins.model.RunIdMigratorTest.java

/** Ensures that legacy timestamps are interpreted in a predictable time zone. */
@BeforeClass//from   w w  w .j a v a2  s. c om
public static void timezone() {
    TimeZone.setDefault(TimeZone.getTimeZone("EST"));
}

From source file:org.geoserver.kml.KMLTest.java

@AfterClass
public static void clearTimeZone() {
    // System.clearProperty("user.timezone");
    TimeZone.setDefault(oldTimeZone);
}

From source file:com.alliander.osgp.signing.server.application.config.SigningServerInitializer.java

@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    try {/*from ww  w .  j  a  v  a2  s.  com*/
        // Force the timezone of application to UTC (required for
        // Hibernate/JDBC)
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

        final Context initialContext = new InitialContext();

        final String logLocation = (String) initialContext.lookup("java:comp/env/osp/signingServer/log-config");
        LogbackConfigurer.initLogging(logLocation);

        final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationContext.class);

        servletContext.addListener(new ContextLoaderListener(rootContext));

    } catch (final NamingException e) {
        throw new ServletException("Naming exception", e);
    } catch (final FileNotFoundException e) {
        throw new ServletException("Logging file not found", e);
    } catch (final JoranException e) {
        throw new ServletException("Logback exception", e);
    }
}

From source file:org.osgp.adapter.protocol.dlms.application.config.ProtocolAdapterDlmsInitializer.java

@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    try {/* w w  w. j av a2 s.c  o m*/
        // Force the timezone of application to UTC (required for
        // Hibernate/JDBC)
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

        final Context initialContext = new InitialContext();

        final String logLocation = (String) initialContext
                .lookup("java:comp/env/osp/osgpAdapterProtocolDlms/log-config");
        LogbackConfigurer.initLogging(logLocation);

        final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationContext.class);

        servletContext.addListener(new ContextLoaderListener(rootContext));

    } catch (final NamingException e) {
        throw new ServletException("naming exception", e);
    } catch (final FileNotFoundException e) {
        throw new ServletException("Logging file not found", e);
    } catch (final JoranException e) {
        throw new ServletException("Logback exception", e);
    }
}

From source file:com.alliander.osgp.adapter.protocol.oslp.application.config.OsgpProtocolAdapterOslpInitializer.java

@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    try {/*w ww. j a  v a  2  s .c o m*/
        // Force the timezone of application to UTC (required for
        // Hibernate/JDBC)
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

        final Context initialContext = new InitialContext();

        final String logLocation = (String) initialContext
                .lookup("java:comp/env/osp/osgpAdapterProtocolOslp/log-config");
        LogbackConfigurer.initLogging(logLocation);

        final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationContext.class);

        servletContext.addListener(new ContextLoaderListener(rootContext));

    } catch (final NamingException e) {
        throw new ServletException("naming exception", e);
    } catch (final FileNotFoundException e) {
        throw new ServletException("Logging file not found", e);
    } catch (final JoranException e) {
        throw new ServletException("Logback exception", e);
    }
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.application.config.OsgpProtocolAdapterOslpInitializer.java

@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    try {//from  w  w  w.j av a  2  s  .  co m
        // Force the timezone of application to UTC (required for
        // Hibernate/JDBC)
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

        final Context initialContext = new InitialContext();

        final String logLocation = (String) initialContext
                .lookup("java:comp/env/osp/osgpAdapterProtocolOslpElster/log-config");
        LogbackConfigurer.initLogging(logLocation);

        final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationContext.class);

        servletContext.addListener(new ContextLoaderListener(rootContext));

    } catch (final NamingException e) {
        throw new ServletException("naming exception", e);
    } catch (final FileNotFoundException e) {
        throw new ServletException("Logging file not found", e);
    } catch (final JoranException e) {
        throw new ServletException("Logback exception", e);
    }
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.application.config.OsgpProtocolAdapterIec61850Initializer.java

@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    try {/*from   w  w  w.j a v  a  2  s . co m*/
        // Force the timezone of application to UTC (required for
        // Hibernate/JDBC)
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

        final Context initialContext = new InitialContext();

        final String logLocation = (String) initialContext
                .lookup("java:comp/env/osp/osgpAdapterProtocolIec61850/log-config");
        LogbackConfigurer.initLogging(logLocation);

        final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationContext.class);

        servletContext.addListener(new ContextLoaderListener(rootContext));

    } catch (final NamingException e) {
        throw new ServletException("naming exception", e);
    } catch (final FileNotFoundException e) {
        throw new ServletException("Logging file not found", e);
    } catch (final JoranException e) {
        throw new ServletException("Logback exception", e);
    }
}

From source file:org.wte4j.FormatDateExpressionTest.java

@BeforeClass
public static void setMEZAsDefaultTimeZone() {
    TimeZone.setDefault(MEZ);
}