Example usage for java.util TimeZone getDefault

List of usage examples for java.util TimeZone getDefault

Introduction

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

Prototype

public static TimeZone getDefault() 

Source Link

Document

Gets the default TimeZone of the Java virtual machine.

Usage

From source file:com.edgenius.wiki.installation.SilenceInstall.java

/**
 * @param silence//  w w  w . ja v  a  2  s  . co  m
 * @param server
 * @param global
 * @param install
 * @throws IllegalAccessException 
 * @throws IllegalArgumentException 
 * @throws NumberFormatException 
 * @throws InvocationTargetException 
 */
private void sync(Properties prop, Server server, GlobalSetting global, Installation install)
        throws NumberFormatException, IllegalArgumentException, IllegalAccessException,
        InvocationTargetException {
    //AUTO detect country and timezone if properties file not set.
    if (StringUtils.isBlank(prop.getProperty("defaultCountry"))) {
        prop.setProperty("defaultCountry", Locale.getDefault().getCountry());
    }
    if (StringUtils.isBlank(prop.getProperty("defaultTimeZone"))) {
        prop.setProperty("defaultTimeZone", TimeZone.getDefault().getID());
    }
    for (Iterator<Object> iter = prop.keySet().iterator(); iter.hasNext();) {
        String key = (String) iter.next();
        if (DEFAULT_KEYS.contains(key))
            continue;

        Object obj = null;
        if (serverFields.contains(key)) {
            obj = server;
        } else if (globalFields.contains(key)) {
            obj = global;
        } else if (installFields.contains(key)) {
            obj = install;
        }
        if (obj == null) {
            log.warn(
                    "Invalid field name {} cann't find in any configuration files - could only configuration option for silence installation",
                    key);
            continue;
        }
        BeanUtils.setProperty(obj, key, getProperty(prop, key));
    }

}

From source file:architecture.ee.component.core.lifecycle.ConfigServiceImpl.java

/**
 * @return//from   w ww  . j  av  a 2 s  .  c  om
 */
public TimeZone getTimeZone() {
    if (timeZone == null)
        if (properties != null) {
            String timeZoneID = (String) properties.get(ApplicationConstants.LOCALE_TIMEZONE_PROP_NAME);
            if (timeZoneID == null)
                timeZone = TimeZone.getDefault();
            else
                timeZone = TimeZone.getTimeZone(timeZoneID);
        } else {
            return TimeZone.getDefault();
        }
    return timeZone;
}

From source file:org.jfree.data.time.YearTest.java

/**
 * Some checks for the getLastMillisecond() method.
 *//*www.  j  a  va 2  s. c om*/
@Test
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Year y = new Year(1970);
    // TODO: Check this result...
    assertEquals(31532399999L, y.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:org.jfree.data.time.junit.MonthTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *//*from   w ww.j  ava 2s.c o m*/
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Month m = new Month(3, 1970);
    assertEquals(5094000000L, m.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:at.alladin.rmbt.client.helper.ControlServerConnection.java

public String requestNewTestConnection(final String host, final String pathPrefix, final int port,
        final boolean encryption, final ArrayList<String> geoInfo, final String uuid, final String clientType,
        final String clientName, final String clientVersion, final JSONObject additionalValues) {

    String errorMsg = null;//w ww .  j  a v  a2 s  .  c  om
    // url to make request to

    clientUUID = uuid;

    hostUri = getUri(encryption, host, pathPrefix, port, Config.RMBT_CONTROL_MAIN_URL);

    System.out.println("Connection to " + hostUri);

    final JSONObject regData = new JSONObject();

    try {
        regData.put("uuid", uuid);
        regData.put("client", clientName);
        regData.put("version", Config.RMBT_VERSION_NUMBER);
        regData.put("type", clientType);
        regData.put("softwareVersion", clientVersion);
        regData.put("softwareRevision", RevisionHelper.getVerboseRevision());
        regData.put("language", Locale.getDefault().getLanguage());
        regData.put("timezone", TimeZone.getDefault().getID());
        regData.put("time", System.currentTimeMillis());
        startTimeNs = System.nanoTime();

        if (geoInfo != null) {
            final JSONObject locData = new JSONObject();
            locData.put("time", geoInfo.get(0));
            locData.put("lat", geoInfo.get(1));
            locData.put("long", geoInfo.get(2));
            locData.put("accuracy", geoInfo.get(3));
            locData.put("altitude", geoInfo.get(4));
            locData.put("bearing", geoInfo.get(5));
            locData.put("speed", geoInfo.get(6));
            locData.put("provider", geoInfo.get(7));

            regData.accumulate("location", locData);
        }

        addToJSONObject(regData, additionalValues);

    } catch (final JSONException e1) {
        errorMsg = "Error gernerating request";
        // e1.printStackTrace();
    }

    // getting JSON string from URL
    final JSONObject response = jParser.sendJSONToUrl(hostUri, regData);

    if (response != null)
        try {
            final JSONArray errorList = response.getJSONArray("error");

            // System.out.println(response.toString(4));

            if (errorList.length() == 0) {

                clientUUID = response.optString("uuid", clientUUID);

                testToken = response.getString("test_token");

                testId = response.getString("test_id");
                testUuid = response.getString("test_uuid");

                testTime = System.currentTimeMillis() + 1000 * response.getLong("test_wait");

                testHost = response.getString("test_server_address");
                testPort = response.getInt("test_server_port");
                testEncryption = response.getBoolean("test_server_encryption");
                serverName = response.optString("test_server_name", null);
                provider = response.optString("provider", null);

                testDuration = response.getInt("test_duration");
                testNumThreads = response.getInt("test_numthreads");
                testNumPings = response.optInt("test_numpings", 10); // pings default to 10

                remoteIp = response.getString("client_remote_ip");

                resultURI = new URI(response.getString("result_url"));
                resultQoSURI = new URI(response.getString("result_qos_url"));
            } else {
                errorMsg = "";
                for (int i = 0; i < errorList.length(); i++) {
                    if (i > 0)
                        errorMsg += "\n";
                    errorMsg += errorList.getString(i);
                }
            }

            // }
        } catch (final JSONException e) {
            errorMsg = "Error parsing server response";
            e.printStackTrace();
        } catch (final URISyntaxException e) {
            errorMsg = "Error parsing server response";
            e.printStackTrace();
        }
    else
        errorMsg = "No response";
    return errorMsg;
}

From source file:com.alkacon.opencms.calendar.CmsSerialDateWidget.java

/**
 * Returns the given timestamp as String formatted in a localized pattern.<p>
 * /*from w  w w.  ja  v a2 s . c  o m*/
 * @param locale the locale for the time format
 * @param messages the messages that contain the time format definitions
 * @param timestamp the time to format
 * @param showDate flag to show the date in the formatted String
 * @param showTime flag to show the time in the formatted String
 * 
 * @return the given timestamp as String formatted in a localized pattern
 */
public static String getCalendarLocalizedTime(Locale locale, CmsMessages messages, long timestamp,
        boolean showDate, boolean showTime) {

    // get the current date & time 
    TimeZone zone = TimeZone.getDefault();
    GregorianCalendar cal = new GregorianCalendar(zone, locale);
    cal.setTimeInMillis(timestamp);
    String datePattern = "";
    if (showDate) {
        datePattern = messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_DATE_FORMAT_0);
        if (showTime) {
            datePattern += " ";
        }
    }
    if (showTime) {
        datePattern += messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_TIME_FORMAT_0);
    }
    // format it nicely according to the localized pattern
    DateFormat df = new SimpleDateFormat(CmsCalendarWidget.getCalendarJavaDateFormat(datePattern));
    return df.format(cal.getTime());
}

From source file:org.jfree.data.time.junit.DayTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *///from w  ww.  j  a  v  a2  s .  c o  m
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Day d = new Day(1, 3, 1970);
    assertEquals(5094000000L, d.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:com.microsoft.tfs.util.datetime.LenientDateTimeParser.java

/**
 * Constructs a lenient parser for the default locale and time zone.
 *//*  w  w w  . j  av  a2s .  co m*/
public LenientDateTimeParser() {
    timeZone = TimeZone.getDefault();
    locale = Locale.getDefault();

    computeFormats();
}

From source file:cn.com.sinosoft.util.time.DurationFormatUtils.java

/**
 * <p>Formats the time gap as a string.</p>
 * /*from   w w  w .  j  av  a  2  s  .co m*/
 * <p>The format used is the ISO8601 period format.</p>
 * 
 * @param startMillis  the start of the duration to format
 * @param endMillis  the end of the duration to format
 * @return the time as a String
 */
public static String formatPeriodISO(long startMillis, long endMillis) {
    return formatPeriod(startMillis, endMillis, ISO_EXTENDED_FORMAT_PATTERN, false, TimeZone.getDefault());
}

From source file:com.serotonin.m2m2.Common.java

public static TimeZone getUserTimeZone(User user) {
    if (user != null)
        return user.getTimeZoneInstance();
    return TimeZone.getDefault();
}