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:morphy.Morphy.java

private void init(File configFile) {
    if (LOG.isInfoEnabled()) {
        LOG.info("Initializing Morphy");
    }//www  .  j  av a  2  s .  co  m

    upsince = System.currentTimeMillis();

    try {
        System.out.println(
                String.format("Attempting to load configuration from path: %s", configFile.getAbsolutePath()));

        this.morphyPreferences = this.loadMorphyConfiguration(configFile);
        this.morphyFileProvider = this.loadMorphyFileProvider(this.morphyPreferences);
    } catch (Exception e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Unable to load configuration due to exception.", e);
        }
        shutdown();
    }

    Thread t = new Thread() {
        public void run() {
            if (LOG.isInfoEnabled()) {
                LOG.info("Server located in timezone " + TimeZoneUtils.getAbbreviation(TimeZone.getDefault()));
            }
        }
    };
    t.start();

    services = new Service[] { DatabaseConnectionService.getInstance(), ThreadService.getInstance(),
            CommandService.getInstance(), SocketConnectionService.getInstance(), ChannelService.getInstance(),
            UserService.getInstance(), ServerListManagerService.getInstance(), GameService.getInstance(),
            RequestService.getInstance() };
}

From source file:fathom.Boot.java

/**
 * Starts Fathom synchronously./*w  ww .j a  v  a  2  s . co  m*/
 */
@Override
public synchronized void start() {
    Preconditions.checkNotNull(getServer());

    String osName = System.getProperty("os.name");
    String osVersion = System.getProperty("os.version");
    log.info("Bootstrapping {} ({})", settings.getApplicationName(), settings.getApplicationVersion());
    Util.logSetting(log, "Fathom", Constants.getVersion());
    Util.logSetting(log, "Mode", settings.getMode().toString());
    Util.logSetting(log, "Operating System", String.format("%s (%s)", osName, osVersion));
    Util.logSetting(log, "Available processors", Runtime.getRuntime().availableProcessors());
    Util.logSetting(log, "Available heap", (Runtime.getRuntime().maxMemory() / (1024 * 1024)) + " MB");

    SimpleDateFormat df = new SimpleDateFormat("z Z");
    df.setTimeZone(TimeZone.getDefault());
    String offset = df.format(new Date());
    Util.logSetting(log, "JVM timezone", String.format("%s (%s)", TimeZone.getDefault().getID(), offset));
    Util.logSetting(log, "JVM locale", Locale.getDefault());

    long startTime = System.nanoTime();
    getServer().start();

    String contextPath = settings.getContextPath();

    if (settings.getHttpsPort() > 0) {
        log.info("https://{}:{}{}", settings.getHttpsListenAddress(), settings.getHttpsPort(), contextPath);
    }
    if (settings.getHttpPort() > 0) {
        log.info("http://{}:{}{}", settings.getHttpListenAddress(), settings.getHttpPort(), contextPath);
    }
    if (settings.getAjpPort() > 0) {
        log.info("ajp://{}:{}{}", settings.getAjpListenAddress(), settings.getAjpPort(), contextPath);
    }

    long delta = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
    String duration;
    if (delta < 1000L) {
        duration = String.format("%s ms", delta);
    } else {
        duration = String.format("%.1f seconds", (delta / 1000f));
    }
    log.info("Fathom bootstrapped {} mode in {}", settings.getMode().toString(), duration);
    log.info("READY.");

}

From source file:architecture.ee.util.ApplicationHelper.java

public static TimeZone getTimeZone() {
    if (isReady()) {
        return getConfigService().getTimeZone();
    } else {//w  w w. j  a  v a  2  s .co  m
        String timeZoneID = getConfigService().getLocalProperty(ApplicationConstants.LOCALE_TIMEZONE_PROP_NAME);
        if (timeZoneID == null)
            return TimeZone.getDefault();
        else
            return TimeZone.getTimeZone(timeZoneID);
    }
}

From source file:org.wikipedia.nirvana.nirvanabot.ReportItem.java

public String toStringWiki(int lineNum) {
    String line = "";
    String timeString = "N/A";
    if (timeDiff > 0) {
        timeString = String.format("%1$tT", timeDiff - TimeZone.getDefault().getRawOffset());
    }//from  w ww .ja  v  a 2  s . c  o m
    String upd = wikiYesNoStringRu(this.updated);
    String arch = wikiYesNoStringRu(this.archived);
    //| 2 ||align='left'| {{user| }}
    String errorStr = wikiErrorStringRu(error.toString(), error != BotError.NONE);
    String statusStr = wikiYesNoCancelStringRu(status.toString(), status.isSuccess(), status.isFailure());
    line = String.format(
            "|-\n|%10$d ||align='left'| [[%1$s]] || %11$d || %2$s || %3$s || %4$d || %5$s || %6$d || %7$s || %8$d || %9$s",
            portal, statusStr, timeString, newPagesFound, upd, pagesArchived, arch, errors, errorStr, lineNum,
            times);
    return line;
}

From source file:de.kurashigegollub.dev.gcatest.Utils.java

public static DateTime getDateTime2Weeks(DateTime dtFrom) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(dtFrom.getValue());
    c.add(Calendar.WEEK_OF_YEAR, 2);
    c.set(Calendar.HOUR_OF_DAY, 23);
    c.set(Calendar.MINUTE, 59);/*from   w w  w . j ava  2s  .  c o m*/
    c.set(Calendar.SECOND, 59);
    c.set(Calendar.MILLISECOND, 999);
    return new DateTime(c.getTime(), TimeZone.getDefault());
}

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

/**
 * Some checks for the getFirstMillisecond() method.
 *//* w  w w . j  a  va  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"));
    Minute m = new Minute(43, 15, 1, 4, 2006);
    assertEquals(1143902580000L, m.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:com.idega.block.cal.renderer.AbstractCompactScheduleRenderer.java

/**
 * <p>/*from  w  ww.  j av a2  s . c o  m*/
 * Draw one day in the schedule
 * </p>
 * 
 * @param context
 *            the FacesContext
 * @param writer
 *            the ResponseWriter
 * @param schedule
 *            the schedule
 * @param day
 *            the day that should be drawn
 * @param cellWidth
 *            the width of the cell
 * @param dayOfWeek
 *            the day of the week
 * @param dayOfMonth
 *            the day of the month
 * @param isWeekend
 *            is it a weekend day?
 * @param isCurrentMonth
 *            is the day in the currently selected month?
 * @param rowspan
 *            the rowspan for the table cell
 * 
 * @throws IOException
 *             when the cell could not be drawn
 */
protected void writeDayCell(FacesContext context, ResponseWriter writer, HtmlSchedule schedule, ScheduleDay day,
        float cellWidth, int dayOfWeek, int dayOfMonth, boolean isWeekend, boolean isCurrentMonth, int rowspan)
        throws IOException {

    final String clientId = schedule.getClientId(context);
    final Map<String, Object> attributes = schedule.getAttributes();
    final FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context);
    final String formId = parentFormInfo == null ? null : parentFormInfo.getFormName();

    TimeZone tz = TimeZone.getDefault();
    final String dayHeaderId = clientId + "_header_" + ScheduleUtil.getDateId(day.getDate(), tz);
    final String dayBodyId = clientId + "_body_" + ScheduleUtil.getDateId(day.getDate(), tz);

    boolean isMonthMode = false;
    boolean isWeekMode = false;

    boolean isFirstInARow = false;

    if (cellWidth == 100f / 6) {
        isMonthMode = true;
    } else if (cellWidth == 50f) {
        isWeekMode = true;
    }

    if ((dayOfWeek != Calendar.SUNDAY) && isMonthMode) {
        writer.startElement(HTML.DIV_ELEM, schedule);
    }
    if (isWeekMode && (dayOfWeek != Calendar.SUNDAY)) {
        writer.startElement(HTML.DIV_ELEM, schedule);
    }
    String dayClass = null;
    if (isWeekMode) {
        dayClass = "";
    } else {
        dayClass = getStyleClass(schedule, isCurrentMonth ? "day" : "inactive-day") + " "
                + getStyleClass(schedule, isWeekend ? "weekend" : "workday");
    }

    // add class for sunday

    if ((dayOfWeek == Calendar.MONDAY) || (dayOfWeek == Calendar.WEDNESDAY) || (dayOfWeek == Calendar.FRIDAY)// ||
    ) {
        isFirstInARow = true;
    }

    if (dayOfWeek == Calendar.SUNDAY) {
        dayClass += " sunday";
    }

    if (dayOfWeek == Calendar.SATURDAY) {
        dayClass += " saturday";
    }

    if ((dayOfWeek != Calendar.SUNDAY) && isMonthMode) {
        writer.writeAttribute(HTML.CLASS_ATTR, "workdaytest", null);

    }
    if ((dayOfWeek != Calendar.SUNDAY) && isWeekMode) {
        if (isFirstInARow) {
            writer.writeAttribute(HTML.CLASS_ATTR, "weekTest firstInAWeekRow", null);
        } else {
            writer.writeAttribute(HTML.CLASS_ATTR, "weekTest secondInAWeekRow", null);
        }
    }

    // determine the height of the day in pixels
    StringBuffer styleBuffer = new StringBuffer();

    int rowHeight = getRowHeight(attributes);
    String myRowHeight = "height: ";
    String myContentHeight = "height: ";

    if (rowHeight > 0) {
        if (isWeekend) {
            myRowHeight += (rowHeight / 2) + "px;";
            myContentHeight += ((rowHeight / 2) - 19) + "px;";
        } else {
            myRowHeight += (rowHeight + 1) + "px;"; //need to add 1 to get the weekends right
            myContentHeight += ((rowHeight + 1) - 18) + "px;"; //18 instead of 19, to get the weekends right
        }
    } else {
        myRowHeight += "100%;";
        myContentHeight += "100%;";
    }

    styleBuffer.append(myRowHeight);

    writer.startElement(HTML.DIV_ELEM, schedule);

    if (cellWidth == 50f) {
        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "day weekMode"), null);
    } else {
        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "day monthMode"), null);
    }

    // day header
    writer.startElement(HTML.DIV_ELEM, schedule);

    if (isMonthMode) {
        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "headerForMonthDay"), null);
    } else if (isWeekMode) {
        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "headerForWeekDay"), null);
    }

    writer.startElement(HTML.DIV_ELEM, schedule);
    writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "header"), null);
    writer.writeAttribute(HTML.STYLE_ATTR, "height: 18px; width: 100%; overflow: hidden", null);
    writer.writeAttribute(HTML.ID_ATTR, dayHeaderId, null);
    //register an onclick event listener to a day header which will capture
    //the date
    if (!schedule.isReadonly() && schedule.isSubmitOnClick()) {
        writer.writeAttribute(HTML.ONMOUSEUP_ATTR,
                "fireScheduleDateClicked(this, event, '" + formId + "', '" + clientId + "');", null);
    }

    writer.writeText(getDateString(context, schedule, day.getDate()), null);
    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);

    // day content
    writer.startElement(HTML.DIV_ELEM, schedule);
    writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "contentForMonthDay"), null);
    writer.startElement(HTML.DIV_ELEM, schedule);
    if (isMonthMode) {

        if ((dayOfWeek == Calendar.SUNDAY) || (dayOfWeek == Calendar.SATURDAY)) {
            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "weekendContent content"), null);
        } else {
            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "workdayContent content"), null);
        }

    } else {
        if ((dayOfWeek == Calendar.SUNDAY) || (dayOfWeek == Calendar.SATURDAY)) {
            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "weekendContentWeekMode content"),
                    null);
        } else {
            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "workdayContentWeekMode content"),
                    null);
        }
    }

    // determine the height of the day content in pixels
    StringBuffer contentStyleBuffer = new StringBuffer();
    contentStyleBuffer.append(myContentHeight);
    //        contentStyleBuffer.append(" width: 100%;");
    writer.writeAttribute(HTML.STYLE_ATTR, contentStyleBuffer.toString(), null);

    writer.startElement(HTML.DIV_ELEM, schedule);
    writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "contentview"), null);

    //this extra div is required, because when a scrollbar is visible and
    //it is clicked, the fireScheduleTimeClicked() method is fired.
    writer.startElement(HTML.DIV_ELEM, schedule);
    writer.writeAttribute(HTML.STYLE_ATTR, "height: 100%; vertical-align: top;", null);

    writer.writeAttribute(HTML.ID_ATTR, dayBodyId, null);

    //register an onclick event listener to a day cell which will capture
    //the date
    if (!schedule.isReadonly() && schedule.isSubmitOnClick()) {
        writer.writeAttribute(HTML.ONMOUSEUP_ATTR,
                "fireScheduleTimeClicked(this, event, '" + formId + "', '" + clientId + "');", null);
    }

    writer.startElement(HTML.DIV_ELEM, schedule);
    writer.writeAttribute(HTML.STYLE_ATTR, "width: 100%;", null);

    writeEntries(context, schedule, day, writer);

    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);

    if ((dayOfWeek != Calendar.SATURDAY) && isMonthMode) {
        writer.endElement(HTML.DIV_ELEM);
    }
    if (cellWidth == 50f && dayOfWeek != Calendar.SATURDAY) {
        writer.endElement(HTML.DIV_ELEM);
    }
}

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

/**
 * Some checks for the getFirstMillisecond() method.
 *//*from  www  . j  a va  2 s.  co  m*/
@Test
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Second s = new Second(15, 43, 15, 1, 4, 2006);
    assertEquals(1143902595000L, s.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:com.idega.block.cal.renderer.ScheduleDetailedDayRenderer.java

/**
 * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext,
 *      javax.faces.component.UIComponent)
 *//*w ww.j av  a  2s. c  o m*/
@Override
public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
    if (!component.isRendered()) {
        return;
    }

    HtmlSchedule schedule = (HtmlSchedule) component;
    ResponseWriter writer = context.getResponseWriter();
    String clientId = schedule.getClientId(context);
    FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context);
    String formId = parentFormInfo == null ? null : parentFormInfo.getFormName();
    int index = 0;
    for (Iterator dayIterator = schedule.getModel().iterator(); dayIterator.hasNext();) {
        ScheduleDay day = (ScheduleDay) dayIterator.next();

        String dayBodyId = clientId + "_body_" + ScheduleUtil.getDateId(day.getDate(), TimeZone.getDefault());
        writer.startElement(HTML.DIV_ELEM, schedule);

        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "column"), null);
        writer.writeAttribute(HTML.STYLE_ATTR, "height: 100%", null);
        writer.startElement(HTML.DIV_ELEM, schedule);
        writer.writeAttribute(HTML.ID_ATTR, dayBodyId, null);
        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "column"), null);

        //register an onclick event listener to a column which will capture
        //the y coordinate of the mouse, to determine the hour of day
        if (!schedule.isReadonly() && schedule.isSubmitOnClick()) {
            writer.writeAttribute(HTML.ONMOUSEUP_ATTR,
                    "fireScheduleTimeClicked(this, event, '" + formId + "', '" + clientId + "');", null);
        }
        writeEntries(context, schedule, day, writer, index);
        writer.endElement(HTML.DIV_ELEM);
        writer.endElement(HTML.DIV_ELEM);
        index++;
    }
}

From source file:eu.hansolo.fx.weatherfx.darksky.DarkSky.java

public DarkSky(final double LATITUDE, final double LONGITUDE) {
    latitude = LATITUDE;//  www.j  a v  a  2  s  . c o m
    longitude = LONGITUDE;
    language = Language.ENGLISH;
    unit = Unit.CA;
    timeZone = TimeZone.getDefault();
    today = new DataPoint();
    forecast = new LinkedList<>();
    alerts = new LinkedList<>();
    lastUpdate = Instant.MIN;
}