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.pingtel.sipviewer.SIPViewerFrame.java

public SIPViewerFrame(boolean createMenu) {
    super("sipviewer");

    this.setSize(800, 600);
    m_sortBranchNodes = false;/* w w w .  j  av  a 2 s .  co  m*/
    this.addWindowListener(new icWindowAdapter());

    // lets get our local time zone used throughout
    localTimeZone = TimeZone.getDefault();

    createComponents();
    layoutComponents();
    if (createMenu)
        initMenu();
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.JdbcReportDataSourceServiceFactory.java

protected TimeZone getTimeZoneByDataSourceTimeZone(String dataSourceTimeZone) {
    String timezoneId = dataSourceTimeZone == null ? "" : dataSourceTimeZone;
    return timezoneId.isEmpty() ? TimeZone.getDefault() : TimeZone.getTimeZone(timezoneId);
}

From source file:net.audumla.astronomy.algorithims.AstronomicalTest.java

@Test
public void testWrapperMethodsMelbourne() throws Exception {
    TimeZone.setDefault(TimeZone.getTimeZone("Australia/Melbourne"));
    CelestialObject sun = CelestialObject.SUN;
    Calendar c = Calendar.getInstance(TimeZone.getDefault());
    c.setTimeInMillis(0);/*from   w ww .j a va2 s  .  c o m*/
    c.set(Calendar.YEAR, 2009);
    c.set(Calendar.MONTH, Calendar.AUGUST);
    c.set(Calendar.DAY_OF_MONTH, 8);

    Date date = c.getTime();
    Geolocation.Location location = new Geolocation.Location(-37.70461920, 145.1030275, 0.0);
    TransitDetails details = sun.getTransitDetails(date, location, Sun.CIVIL);
    logger.debug("Melbourne");
    logger.debug("Date    : " + date);
    logger.debug("Julian  : " + new JulianDate(date).julian());
    logger.debug("Sunrise : Algorithms: " + details.getRiseTime() + " : " + details.getRiseTime().getTime());
    logger.debug("Sunset  : Algorithms: " + details.getSetTime() + " : " + details.getSetTime().getTime());
    Assert.assertEquals(details.getRiseTime().getTime(), 1249677914422l, 1000);
    Assert.assertEquals(details.getSetTime().getTime(), 1249718740422l, 1000);
}

From source file:fiskinfoo.no.sintef.fiskinfoo.Baseclasses.ToolEntry.java

public ToolEntry(List<Point> coordinates, String vesselName, String vesselPhone, String vesselEmail,
        ToolType toolType, String setupDateTime, String regNum, String contactPersonName,
        String contactPersonPhone, String contactPersonEmail) {
    this.coordinates = coordinates;
    this.geometry = coordinates.size() > 1 ? GeometryType.LINESTRING : GeometryType.POINT;
    this.VesselName = vesselName;
    this.VesselPhone = vesselPhone;
    this.ToolTypeCode = toolType;
    this.toolStatus = ToolEntryStatus.STATUS_UNREPORTED;
    this.RegNum = regNum;
    this.ContactPersonName = contactPersonName;
    this.ContactPersonPhone = contactPersonPhone;
    this.ContactPersonEmail = contactPersonEmail;
    this.VesselEmail = vesselEmail;

    this.ToolId = UUID.randomUUID().toString(); //UUID.fromString("Fiskinfo" + VesselName + SetupDateTime).toString();
    this.id = this.ToolId;

    Date setupDate = null;//from  w w w . j  a v a  2 s .c  o  m
    Date lastChangedDate = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.getDefault());
    String lastChangedDateString;
    String setupDateString;

    sdf.setTimeZone(TimeZone.getDefault());

    try {
        setupDate = sdf.parse(setupDateTime);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    setupDateString = sdf.format(setupDate);
    lastChangedDateString = sdf.format(lastChangedDate);

    this.SetupDateTime = setupDateString.substring(0, setupDateString.indexOf('.')).concat("Z");
    this.LastChangedBySource = lastChangedDateString.concat("Z");
    this.LastChangedDateTime = lastChangedDateString.concat("Z");

}

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

/**
 * Creates a new dataset.
 */
public TimeTableXYDataset() {
    // defer argument checking
    this(TimeZone.getDefault(), Locale.getDefault());
}

From source file:be.ibridge.kettle.trans.step.excelinput.ExcelInput.java

private Row fillRow(Row baserow, int startcolumn, ExcelInputRow excelInputRow) throws KettleException {
    Row r = new Row(baserow);

    // Keep track whether or not we handled an error for this line yet.
    boolean errorHandled = false;

    // Set values in the row...
    for (int i = startcolumn; i < excelInputRow.cells.length && i - startcolumn < r.size(); i++) {
        Cell cell = excelInputRow.cells[i];

        int rowcolumn = i - startcolumn;

        Value v = r.getValue(rowcolumn);

        try {//from w  ww. j a va  2  s  .c om
            checkType(cell, v);
        } catch (KettleException ex) {
            if (!meta.isErrorIgnored())
                throw ex;
            logBasic("Warning processing [" + v + "] from Excel file [" + data.filename + "] : "
                    + ex.getMessage());
            if (!errorHandled) {
                data.errorHandler.handleLineError(excelInputRow.rownr, excelInputRow.sheetName);
                errorHandled = true;
            }

            if (meta.isErrorLineSkipped()) {
                r.setIgnore();
                return r;
            }
        }

        CellType cellType = cell.getType();
        if (CellType.BOOLEAN.equals(cellType) || CellType.BOOLEAN_FORMULA.equals(cellType)) {
            v.setValue(((BooleanCell) cell).getValue());
        } else {
            if (CellType.DATE.equals(cellType) || CellType.DATE_FORMULA.equals(cellType)) {
                Date date = ((DateCell) cell).getDate();
                long time = date.getTime();
                int offset = TimeZone.getDefault().getOffset(time);
                v.setValue(new Date(time - offset));
            } else {
                if (CellType.LABEL.equals(cellType) || CellType.STRING_FORMULA.equals(cellType)) {
                    v.setValue(((LabelCell) cell).getString());
                    switch (meta.getField()[rowcolumn].getTrimType()) {
                    case ExcelInputMeta.TYPE_TRIM_LEFT:
                        v.ltrim();
                        break;
                    case ExcelInputMeta.TYPE_TRIM_RIGHT:
                        v.rtrim();
                        break;
                    case ExcelInputMeta.TYPE_TRIM_BOTH:
                        v.trim();
                        break;
                    default:
                        break;
                    }
                } else {
                    if (CellType.NUMBER.equals(cellType) || CellType.NUMBER_FORMULA.equals(cellType)) {
                        v.setValue(((NumberCell) cell).getValue());
                    } else {
                        if (log.isDetailed())
                            logDetailed("Unknown type : " + cell.getType().toString() + " : ["
                                    + cell.getContents() + "]");
                        v.setNull();
                    }
                }
            }
        }

        ExcelInputField field = meta.getField()[rowcolumn];

        // Change to the appropriate type if needed...
        //
        try {
            if (v.getType() != field.getType()) {
                switch (v.getType()) {
                // Use case: we find a String: convert it using the supplied format to the desired type...
                //
                case Value.VALUE_TYPE_STRING:
                    switch (field.getType()) {
                    case Value.VALUE_TYPE_DATE:
                        v.str2dat(field.getFormat());
                        break;
                    case Value.VALUE_TYPE_NUMBER:
                        v.str2num(field.getFormat(), field.getDecimalSymbol(), field.getGroupSymbol(),
                                field.getCurrencySymbol());
                        break;
                    default:
                        v.setType(field.getType());
                        break;
                    }
                    break;

                // Use case: we find a numeric value: convert it using the supplied format to the desired data type...
                //
                case Value.VALUE_TYPE_NUMBER:
                case Value.VALUE_TYPE_INTEGER:
                    switch (field.getType()) {
                    case Value.VALUE_TYPE_STRING:
                        v.num2str(field.getFormat(), field.getDecimalSymbol(), field.getGroupSymbol(),
                                field.getCurrencySymbol());
                        break;
                    case Value.VALUE_TYPE_DATE:
                        v.num2str("#").str2dat(field.getFormat());
                        break;
                    default:
                        v.setType(field.getType());
                        break;
                    }
                    break;
                // Use case: we find a date: convert it using the supplied format to String...
                //
                case Value.VALUE_TYPE_DATE:
                    switch (field.getType()) {
                    case Value.VALUE_TYPE_STRING:
                        v.dat2str(field.getFormat());
                        break;
                    default:
                        v.setType(field.getType());
                        break;
                    }
                    break;
                default:
                    v.setType(field.getType());
                }
            }
        } catch (KettleException ex) {
            if (!meta.isErrorIgnored())
                throw ex;
            logBasic("Warning processing [" + v + "] from Excel file [" + data.filename + "] : "
                    + ex.toString());
            if (!errorHandled) // check if we didn't log an error already for this one.
            {
                data.errorHandler.handleLineError(excelInputRow.rownr, excelInputRow.sheetName);
                errorHandled = true;
            }

            if (meta.isErrorLineSkipped()) {
                r.setIgnore();
                return r;
            } else {
                v.setNull();
            }
        }

        // Set the meta-data of the field: length and precision
        //
        v.setLength(meta.getField()[rowcolumn].getLength(), meta.getField()[rowcolumn].getPrecision());
    }

    // Do we need to include the filename?
    if (meta.getFileField() != null && meta.getFileField().length() > 0) {
        Value value = new Value(meta.getFileField(), data.filename);
        value.setLength(data.maxfilelength);
        r.addValue(value);
    }

    // Do we need to include the sheetname?
    if (meta.getSheetField() != null && meta.getSheetField().length() > 0) {
        Value value = new Value(meta.getSheetField(), excelInputRow.sheetName);
        value.setLength(data.maxsheetlength);
        r.addValue(value);
    }

    // Do we need to include the sheet rownumber?
    if (meta.getSheetRowNumberField() != null && meta.getSheetRowNumberField().length() > 0) {
        Value value = new Value(meta.getSheetRowNumberField(), Value.VALUE_TYPE_INTEGER);
        value.setValue(data.rownr);
        r.addValue(value);
    }

    // Do we need to include the rownumber?
    if (meta.getRowNumberField() != null && meta.getRowNumberField().length() > 0) {
        Value value = new Value(meta.getRowNumberField(), Value.VALUE_TYPE_INTEGER);
        value.setValue(linesWritten + 1);
        r.addValue(value);
    }

    return r;
}

From source file:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java

/**
 * /* ww  w  .j  a v a 2s  .c o m*/
 */
protected void fillDateFormat() {

    String currentFormat = AppPreferences.getRemote().get("ui.formatting.scrdateformat", null);

    TimeZone tz = TimeZone.getDefault();
    DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
    dateFormatter.setTimeZone(tz);
    String dateStr = dateFormatter.format(Calendar.getInstance().getTime());
    Character ch = null;
    for (int i = 0; i < 10; i++) {
        if (!StringUtils.isNumeric(dateStr.substring(i, i + 1))) {
            ch = dateStr.charAt(i);
            break;
        }
    }

    if (ch != null) {
        boolean skip = false;
        Vector<String> formats = new Vector<String>();
        if (ch == '/') {
            addFormats(formats, '/');
            skip = true;
        }
        if (ch != '.') {
            addFormats(formats, '.');
            skip = true;
        }
        if (ch != '-') {
            addFormats(formats, '-');
            skip = true;
        }

        if (!skip) {
            addFormats(formats, ch);
        }

        int selectedInx = 0;
        int inx = 0;
        DefaultComboBoxModel model = (DefaultComboBoxModel) dateFieldCBX.getModel();
        for (String fmt : formats) {
            model.addElement(fmt);
            if (currentFormat != null && currentFormat.equals(fmt)) {
                selectedInx = inx;
            }
            inx++;
        }
        dateFieldCBX.getComboBox().setSelectedIndex(selectedInx);
    }
}

From source file:tsauto.TcpMsgReceiverAlphaFlashStream.java

/**
 * Default constructor.//from w  ww  .ja v  a2s. c o m
 */
public TcpMsgReceiverAlphaFlashStream(DukasConsole console) {
    this.console = console;
    dateFormatter = new java.text.SimpleDateFormat(DATE_FORMAT);
    dateFormatter.setTimeZone(TimeZone.getDefault());
}

From source file:com.github.anba.es6draft.util.TestGlobals.java

protected TimeZone getTimeZone(TEST test) {
    return TimeZone.getDefault();
}

From source file:se.vgregion.portal.notes.calendar.controllers.NotesCalendarViewController.java

/**
 * Displays the calendar events for the logged in user.
 *
 * @param model    the model//www .java2s  .  co  m
 * @param request  the portletRequest
 * @param response the portletResponse
 * @return the view to display
 */
@RenderMapping
public String displayCalendarEvents(ModelMap model, RenderRequest request, RenderResponse response) {

    // It would seem that Joda Times DateTimeZone does not use Sun:s TimeZone.getDefault (user.timezone) as its
    // often claims but defaults to timezone UTC. So therefor we do this:
    DateTimeZone.setDefault(DateTimeZone.forTimeZone(TimeZone.getDefault()));
    // ... getting the value set in the java_opt - setting it as default for JT.

    String userId = portletData.getUserId(request);
    LOGGER.debug("Userid: {}", userId);
    CalendarEventsPeriod displayPeriod = (CalendarEventsPeriod) model.get(displayPeriodKey);
    if (displayPeriod == null) {
        DateTime startDate = new DateTime().withDayOfWeek(DateTimeConstants.MONDAY).withHourOfDay(0)
                .withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0);
        displayPeriod = new CalendarEventsPeriod(startDate, CalendarEventsPeriod.DEFAULT_PERIOD_LENGTH);
        model.put(displayPeriodKey, displayPeriod);
    }
    try {
        Map<String, Future<CalendarEvents>> futureCalendarEvents = new HashMap<String, Future<CalendarEvents>>();

        // Initialize CalendarEvents
        CalendarEvents events = new CalendarEvents();
        events.setCalendarItems(new ArrayList<CalendarItem>());

        // Retrieve asynchronously
        futureCalendarEvents.put("VGR", calendarService.getFutureCalendarEvents(userId, displayPeriod));

        // Get from Google, asynchronously
        //            String selectedCalendars = request.getPreferences().getValue(this.SELECTED_GOOGLE_CALENDARS, "");
        //            List<String> selectedCalendarsList = Arrays.asList(stringToArray(selectedCalendars));
        //            futureCalendarEvents.put("Google", googleCalendarService.getFutureCalendarEvents(userId, displayPeriod,
        //                    selectedCalendarsList));

        // Get from other sources, asynchronously.
        Map<String, String> externalSources = getExternalSources(request.getPreferences());
        for (Map.Entry<String, String> externalSource : externalSources.entrySet()) {
            futureCalendarEvents.put(externalSource.getKey(),
                    calendarService.getFutureCalendarEventsFromIcalUrl(externalSource.getValue(), displayPeriod,
                            externalSource.getKey()));
        }

        // Now that we have a list of Future objects which all are processed concurrently we start to "get()" them.
        List<String> failedRetrievals = new ArrayList<String>();
        for (Map.Entry<String, Future<CalendarEvents>> futureCalendarEvent : futureCalendarEvents.entrySet()) {
            try {
                Future<CalendarEvents> value = futureCalendarEvent.getValue();
                CalendarEvents calendarEvents = value.get(15, TimeUnit.SECONDS);
                if (calendarEvents != null) {
                    List<CalendarItem> calendarItems = calendarEvents.getCalendarItems();
                    if (calendarItems != null) {
                        events.getCalendarItems().addAll(calendarItems);
                    }
                }
            } catch (Exception ex) {
                if (userId.equals("lifra1")) {
                    LOGGER.warn("Failed to get a calendar for user " + userId + ". " + ex.getMessage());
                } else {
                    LOGGER.warn("Failed to get a calendar for user " + userId + ". " + ex.getMessage(), ex);
                }
                failedRetrievals.add(futureCalendarEvent.getKey());
            }
        }

        if (failedRetrievals.size() > 0) {
            String errorMessage = "Fljande hmtningar misslyckades: "
                    + StringUtils.arrayToCommaDelimitedString(failedRetrievals.toArray()) + ".";
            model.addAttribute("errorMessage", errorMessage);
        }

        List<List<CalendarItem>> calendarItems = events.getCalendarItemsGroupedByStartDate();
        model.put("displayPeriodText", getFormattedDateIntervalToTitle(displayPeriod, locale));
        model.put("calendarItems", calendarItems);
        model.put("randomNumber", random.nextInt());
        return VIEW;
    } catch (RuntimeException ex) {
        LOGGER.error(ex.getMessage(), ex);
        return NO_CALENDAR_VIEW;
    } catch (Exception ex) {
        LOGGER.error(ex.getMessage(), ex);
        return NO_CALENDAR_VIEW;
    }
}