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.bdb.weather.display.day.DayXYPlotPane.java

/**
 * Load the data into the JFreeChart time series and into the Table Model
 * /*ww w .ja  v a 2 s.  c  o m*/
 * @param records The list of historical records
 */
protected void loadDataSeries(List<HistoricalRecord> records) {
    entries.stream().forEach((entry) -> {
        entry.timeSeries.clear();
    });

    ObservableList<HistoricalRecord> dataModel = FXCollections.observableList(records);
    dataTable.setItems(dataModel);

    getPlot().getRangeAxis().setAutoRange(true);

    records.stream().forEach((r) -> {
        RegularTimePeriod p = RegularTimePeriod.createInstance(Minute.class,
                TimeUtils.localDateTimeToDate(r.getTime()), TimeZone.getDefault());

        entries.stream().forEach((entry) -> {
            Measurement m = entry.seriesInfo.getValue(r);
            if (m != null) {
                entry.timeSeries.add(p, m.get());
            }
        });
    });

    displaySeries(datasetLeft, datasetRight);
}

From source file:com.ah.ui.actions.monitor.OneTimePasswordAction.java

private void emailOTPS() {
    int count = 0;

    /*/*www  .j  av  a2  s .  c  om*/
     * get mail settings
     */
    List<MailNotification> mailNotification = QueryUtil.executeQuery(MailNotification.class, null, null,
            getDomain().getId());

    if (!mailNotification.isEmpty()) {
        String serverName = mailNotification.get(0).getServerName();
        String mailFrom = mailNotification.get(0).getMailFrom();

        if (serverName == null || serverName.equals("")) {
            addActionError(MgrUtil.getUserMessage("error.gml.email.setting.wrong", "SMTP server"));
            return;
        }

        if (mailFrom == null || mailFrom.equals("")) {
            addActionError(MgrUtil.getUserMessage("error.gml.email.setting.wrong", "Source mail address"));
        }

    } else {
        addActionError(MgrUtil.getUserMessage("error.gml.email.setting.wrong", "Email setting"));
        return;
    }

    /*
     * set mail
     */
    if (isAllItemsSelected()) {
        List<OneTimePassword> passwords = QueryUtil.executeQuery(OneTimePassword.class,
                new SortParams("oneTimePassword"), filterParams, getDomainId());

        for (OneTimePassword otp : passwords) {
            if (emailOTP(otp, mailNotification)) {
                count++;
                otp.setDateSentStamp(System.currentTimeMillis());
                otp.setDateTimeZone(
                        getDomain() != null ? getDomain().getTimeZoneString() : TimeZone.getDefault().getID());
            }
        }
        try {
            QueryUtil.bulkUpdateBos(passwords);
        } catch (Exception e) {
            log.error("bulkUpdateBos failed ", e);
        }

    } else {
        for (Long id : getAllSelectedIds()) {
            OneTimePassword otp;
            try {
                otp = findBoById(OneTimePassword.class, id);

                if (otp == null) {
                    continue;
                }

                if (emailOTP(otp, mailNotification)) {
                    count++;
                    otp.setDateSentStamp(System.currentTimeMillis());
                    otp.setDateTimeZone(getDomain() != null ? getDomain().getTimeZoneString()
                            : TimeZone.getDefault().getID());
                    QueryUtil.updateBo(otp);
                }
            } catch (Exception e) {
                log.error("Cannot get user(id=" + id + ") from database", e);
            }
        }
    }

    if (count > 1) {
        addActionMessage(
                MgrUtil.getUserMessage(OBJECT_EMAIL, formatNum(count) + " devices registration code have "));
    } else {
        addActionMessage(
                MgrUtil.getUserMessage(OBJECT_EMAIL, formatNum(count) + " device registration code has "));
    }
}

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

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

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

/**
 * Some checks for the getEnd() method.//from w w  w  .j a  va  2  s  .  c om
 */
@Test
public void testGetEnd() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome"));
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 16, 3, 47, 59);
    cal.set(Calendar.MILLISECOND, 999);
    Minute m = new Minute(47, 3, 16, 1, 2006);
    assertEquals(cal.getTime(), m.getEnd());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:org.ngrinder.perftest.controller.PerfTestController.java

/**
 * Add the various default configuration values on the model.
 *
 * @param model model to which put the default values
 *//*  w ww .ja v a  2  s .c o m*/
public void addDefaultAttributeOnModel(ModelMap model) {
    model.addAttribute(PARAM_AVAILABLE_RAMP_UP_TYPE, RampUp.values());
    model.addAttribute(PARAM_MAX_VUSER_PER_AGENT, agentManager.getMaxVuserPerAgent());
    model.addAttribute(PARAM_MAX_RUN_COUNT, agentManager.getMaxRunCount());
    model.addAttribute(PARAM_SECURITY_MODE, getConfig().isSecurityEnabled());
    model.addAttribute(PARAM_MAX_RUN_HOUR, agentManager.getMaxRunHour());
    model.addAttribute(PARAM_SAFE_FILE_DISTRIBUTION, getConfig().getControllerProperties()
            .getPropertyBoolean(ControllerConstants.PROP_CONTROLLER_SAFE_DIST));
    String timeZone = getCurrentUser().getTimeZone();
    int offset;
    if (StringUtils.isNotBlank(timeZone)) {
        offset = TimeZone.getTimeZone(timeZone).getOffset(System.currentTimeMillis());
    } else {
        offset = TimeZone.getDefault().getOffset(System.currentTimeMillis());
    }
    model.addAttribute(PARAM_TIMEZONE_OFFSET, offset);
}

From source file:com.xpfriend.fixture.cast.temp.ObjectValidatorBase.java

private Object toDate(String actual) {
    Date date;/*www. jav  a2  s .  co  m*/
    if ((date = parse(DateFormat.getDateInstance(), actual)) != null) {
        return date;
    }
    if ((date = parse(DateFormat.getDateTimeInstance(), actual)) != null) {
        return date;
    }

    TimeZone timeZone = TimeZone.getDefault();
    for (int i = 0; i < DATEFORMATS.length; i++) {
        DateFormat dateFormat = dateFormatter.getDateFormat(DATEFORMATS[i], timeZone);
        if ((date = parse(dateFormat, actual)) != null) {
            return date;
        }
    }
    return actual;
}

From source file:com.microsoft.windowsazure.messaging.Registration.java

/**
 * Parses an UTC date string into a Date object
 * @param dateString The date string to parse
 * @return The Date object/*from   ww w .j a  va2s  .  co  m*/
 * @throws java.text.ParseException
 */
private static Date UTCDateStringToDate(String dateString) throws ParseException {
    // Change Z to +00:00 to adapt the string to a format
    // that can be parsed in Java
    String s = dateString.replace("Z", "+00:00");
    try {
        // Remove the ":" character to adapt the string to a
        // format that can be parsed in Java
        s = s.substring(0, 26) + s.substring(27);
    } catch (IndexOutOfBoundsException e) {
        throw new ParseException("The 'updated' value has an invalid format", 26);
    }

    // Parse the well-formatted date string
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSSZ", Locale.getDefault());
    dateFormat.setTimeZone(TimeZone.getDefault());
    Date date = dateFormat.parse(s);

    return date;

}

From source file:com.rogchen.common.xml.UtilDateTime.java

public static Timestamp getMonthStart(Timestamp stamp, int daysLater, int monthsLater) {
    return getMonthStart(stamp, daysLater, monthsLater, TimeZone.getDefault(), Locale.getDefault());
}

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

/**
 * This method provides a check for the bounds calculated using the
 * {@link DatasetUtilities#findDomainBounds(org.jfree.data.xy.XYDataset,
 * java.util.List, boolean)} method./*from ww  w  .  jav  a 2 s  .c om*/
 */
@Test
public void testFindDomainBounds() {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    List visibleSeriesKeys = new java.util.ArrayList();
    Range r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true);
    assertNull(r);

    TimeSeries s1 = new TimeSeries("S1");
    dataset.addSeries(s1);
    visibleSeriesKeys.add("S1");
    r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true);
    assertNull(r);

    // store the current time zone
    TimeZone saved = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/Paris"));

    s1.add(new Year(2008), 8.0);
    r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true);
    assertEquals(1199142000000.0, r.getLowerBound(), EPSILON);
    assertEquals(1230764399999.0, r.getUpperBound(), EPSILON);

    TimeSeries s2 = new TimeSeries("S2");
    dataset.addSeries(s2);
    s2.add(new Year(2009), 9.0);
    s2.add(new Year(2010), 10.0);
    r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true);
    assertEquals(1199142000000.0, r.getLowerBound(), EPSILON);
    assertEquals(1230764399999.0, r.getUpperBound(), EPSILON);

    visibleSeriesKeys.add("S2");
    r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true);
    assertEquals(1199142000000.0, r.getLowerBound(), EPSILON);
    assertEquals(1293836399999.0, r.getUpperBound(), EPSILON);

    // restore the default time zone
    TimeZone.setDefault(saved);
}

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

/**
 * Some checks for the getLastMillisecond() method.
 *///from  www  . j a  va2s .co  m
public void testGetLastMillisecond() {
    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(7772399999L, m.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}