Example usage for java.text DateFormat SHORT

List of usage examples for java.text DateFormat SHORT

Introduction

In this page you can find the example usage for java.text DateFormat SHORT.

Prototype

int SHORT

To view the source code for java.text DateFormat SHORT.

Click Source Link

Document

Constant for short style pattern.

Usage

From source file:net.pmarks.chromadoze.MainFragment.java

@Override
public void onNoiseServicePercentChange(int percent, Date stopTimestamp, int stopReasonId) {
    boolean showGenerating = false;
    boolean showStopReason = false;
    if (percent < 0) {
        mPercentBar.setVisibility(View.INVISIBLE);
        // While the service is stopped, show what event caused it to stop.
        showStopReason = (stopReasonId != 0);
    } else if (percent < 100) {
        mPercentBar.setVisibility(View.VISIBLE);
        mPercentBar.setProgress(percent);
        showGenerating = true;/* w w  w  .jav a 2 s.  c o m*/
    } else {
        mPercentBar.setVisibility(View.INVISIBLE);
        // While the service is active, only the restart event is worth showing.
        showStopReason = (stopReasonId == R.string.stop_reason_restarted);
    }
    if (showStopReason) {
        // Expire the message after 12 hours, to avoid date ambiguity.
        long diff = new Date().getTime() - stopTimestamp.getTime();
        if (diff > 12 * 3600 * 1000L) {
            showStopReason = false;
        }
    }
    if (showGenerating) {
        mStateText.setText(R.string.generating);
    } else if (showStopReason) {
        String timeFmt = DateFormat.getTimeInstance(DateFormat.SHORT).format(stopTimestamp);
        mStateText.setText(timeFmt + ": " + getString(stopReasonId));
    } else {
        mStateText.setText("");
    }
}

From source file:SpinnerTest.java

public SpinnerFrame() {
    setTitle("SpinnerTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    JPanel buttonPanel = new JPanel();
    okButton = new JButton("Ok");
    buttonPanel.add(okButton);// w w  w  .j  ava  2 s  . com
    add(buttonPanel, BorderLayout.SOUTH);

    mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayout(0, 3));
    add(mainPanel, BorderLayout.CENTER);

    JSpinner defaultSpinner = new JSpinner();
    addRow("Default", defaultSpinner);

    JSpinner boundedSpinner = new JSpinner(new SpinnerNumberModel(5, 0, 10, 0.5));
    addRow("Bounded", boundedSpinner);

    String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

    JSpinner listSpinner = new JSpinner(new SpinnerListModel(fonts));
    addRow("List", listSpinner);

    JSpinner reverseListSpinner = new JSpinner(new SpinnerListModel(fonts) {
        public Object getNextValue() {
            return super.getPreviousValue();
        }

        public Object getPreviousValue() {
            return super.getNextValue();
        }
    });
    addRow("Reverse List", reverseListSpinner);

    JSpinner dateSpinner = new JSpinner(new SpinnerDateModel());
    addRow("Date", dateSpinner);

    JSpinner betterDateSpinner = new JSpinner(new SpinnerDateModel());
    String pattern = ((SimpleDateFormat) DateFormat.getDateInstance()).toPattern();
    betterDateSpinner.setEditor(new JSpinner.DateEditor(betterDateSpinner, pattern));
    addRow("Better Date", betterDateSpinner);

    JSpinner timeSpinner = new JSpinner(new SpinnerDateModel());
    pattern = ((SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT)).toPattern();
    timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, pattern));
    addRow("Time", timeSpinner);

    JSpinner permSpinner = new JSpinner(new PermutationSpinnerModel("meat"));
    addRow("Word permutations", permSpinner);
}

From source file:com.hygenics.parser.ExecuteSQL.java

/**
 * Executes SQL Commands, Unthreaded in Implementation here
 *//*  w  ww  . ja  v a 2  s . c om*/
public void execute() {

    //check variables to see if they are actually system related

    if (sql != null && sql.size() > 0) {
        for (String cmd : sql) {
            try {
                log.info("Executing: " + cmd);
                this.template.execute(cmd);
            } catch (Exception e) {
                e.printStackTrace();
                if (kill) {
                    break;
                }
            }
        }
    }

    if (move != null && move.size() > 0) {
        for (String key : move.keySet()) {
            String schema = key
                    + DateFormat.getDateInstance(DateFormat.SHORT).format(Calendar.getInstance().getTime());
            template.execute(
                    "CREATE SCHEMA " + Properties.getProperty(key) + "_" + Properties.getProperty(schema));
            for (String table : move.get(key)) {
                template.execute(
                        "INSERT INTO " + Properties.getProperty(key) + "_" + Properties.getProperty(schema)
                                + "." + Properties.getProperty(table) + " VALUES(SELECT * FROM "
                                + Properties.getProperty(key) + "." + Properties.getProperty(table) + ")");
            }
        }
    }

    if (tableMappings != null) {
        for (String tableSQL : tableMappings.keySet()) {
            int lp = 0;
            String sql = null;
            String tableSelect = tableMappings.get(tableSQL);

            if (idval != null && idval.toLowerCase().trim().contains("property:")) {
                idval = System.getProperty(idval.split(":")[1].trim());
            }

            if (tableColumn.toLowerCase().trim().contains("property:")) {
                tableColumn = System.getProperty(tableColumn.split(":")[1].trim());
            }

            if (tableSchema != null && tableSchema.toLowerCase().contains("property:")) {
                tableSchema = System.getProperty(tableSchema.split(":")[1].trim());
            }

            if (tableIdentifier != null && tableIdentifier.toLowerCase().contains("property:")) {
                tableIdentifier = System.getProperty(tableIdentifier.split(":")[1].trim());
            }

            if (tableSelect.trim().toLowerCase().contains("property:")) {
                sql = "SELECT * FROM " + System.getProperty(tableSelect.split(":")[1]) + " WHERE "
                        + tableIdentifier + " LIKE '" + idval + "'";
            } else {
                sql = tableSelect;
            }

            // log.info("Executing "+sql);

            for (String record : template.getJsonData(sql)) {
                JsonObject tj = JsonObject.readFrom(record);
                if (schemaColumn != null) {
                    tableSchema = tj.get(schemaColumn).asString();
                }

                if (tj.get(tableColumn) != null && tableSchema.trim().length() > 0) {
                    String temp = Properties.getProperty(tableSQL.replace("$SCHEMA$", tableSchema));
                    temp = Properties
                            .getProperty(temp.replace("$TABLE$", tj.get(tableColumn).asString().trim()));
                    log.info("Executing " + temp);

                    if (lp > 0 && replaces != null) {
                        for (String key : replaces.keySet()) {
                            log.info(key + " " + replaces.get(key));
                            temp = temp.replaceAll(key, replaces.get(key));
                            log.info(temp);
                        }
                        log.info("Final SQL " + temp);
                    }

                    template.execute(temp);
                } else {
                    log.warn("Table name was problematic.");
                }
                lp += 1;
            }

            log.info("Tables Changed: " + lp);
        }
    }
}

From source file:com.concursive.connect.web.modules.calendar.utils.CalendarViewUtils.java

public static CalendarView generateCalendarView(Connection db, CalendarBean calendarInfo, Project project,
        User user, String filter) throws SQLException {

    // Generate a new calendar
    CalendarView calendarView = new CalendarView(calendarInfo, user.getLocale());

    if (calendarInfo.getShowHolidays()) {
        // Add some holidays based on the user locale
        calendarView.addHolidays();/*from w  w w . j av a  2s  . co m*/
    }

    // Set Start and End Dates for the view, use the user's timezone offset
    // (always use Locale.US which matches the URL format)
    String startValue = calendarView.getCalendarStartDate(calendarInfo.getSource());
    LOG.debug(startValue);
    String userStartValue = DateUtils.getUserToServerDateTimeString(calendarInfo.getTimeZone(),
            DateFormat.SHORT, DateFormat.LONG, startValue, Locale.US);
    LOG.debug(userStartValue);
    Timestamp startDate = DatabaseUtils.parseTimestamp(userStartValue);
    startDate.setNanos(0);
    LOG.debug(startDate);

    Timestamp endDate = DatabaseUtils.parseTimestamp(
            DateUtils.getUserToServerDateTimeString(calendarInfo.getTimeZone(), DateFormat.SHORT,
                    DateFormat.LONG, calendarView.getCalendarEndDate(calendarInfo.getSource()), Locale.US));
    endDate.setNanos(0);

    if (ProjectUtils.hasAccess(project.getId(), user, "project-tickets-view")) {
        // Show open and closed tickets
        TicketList ticketList = new TicketList();
        ticketList.setProjectId(project.getId());
        ticketList.setOnlyAssigned(true);
        ticketList.setAlertRangeStart(startDate);
        ticketList.setAlertRangeEnd(endDate);
        if ("pending".equals(filter)) {
            ticketList.setOnlyOpen(true);
        } else if ("completed".equals(filter)) {
            ticketList.setOnlyClosed(true);
        }

        // Retrieve the tickets that meet the criteria
        ticketList.buildList(db);
        for (Ticket thisTicket : ticketList) {
            if (thisTicket.getEstimatedResolutionDate() != null) {
                String alertDate = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user),
                        DateFormat.SHORT, thisTicket.getEstimatedResolutionDate());
                calendarView.addEvent(alertDate, CalendarEventList.EVENT_TYPES[11], thisTicket);
            }
        }

        // Retrieve the dates in which a ticket has been resolved
        HashMap<String, Integer> dayEvents = ticketList.queryRecordCount(db, UserUtils.getUserTimeZone(user));
        for (String thisDay : dayEvents.keySet()) {
            calendarView.addEventCount(thisDay, CalendarEventList.EVENT_TYPES[CalendarEventList.TICKET],
                    dayEvents.get(thisDay));
        }
    }
    if (ProjectUtils.hasAccess(project.getId(), user, "project-plan-view")) {
        // List open and closed Requirements
        RequirementList requirementList = new RequirementList();
        requirementList.setProjectId(project.getId());
        requirementList.setBuildAssignments(false);
        requirementList.setAlertRangeStart(startDate);
        requirementList.setAlertRangeEnd(endDate);
        if ("pending".equals(filter)) {
            requirementList.setOpenOnly(true);
        } else if ("completed".equals(filter)) {
            requirementList.setClosedOnly(true);
        }

        // Retrieve the requirements that meet the criteria
        requirementList.buildList(db);
        // @todo fix timezone for query counts
        requirementList.buildPlanActivityCounts(db);
        for (Requirement thisRequirement : requirementList) {
            // Display Milestone startDate
            if (thisRequirement.getStartDate() != null) {
                String start = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user),
                        DateFormat.SHORT, thisRequirement.getStartDate());
                calendarView.addEvent(start, CalendarEventList.EVENT_TYPES[16], thisRequirement);
            }
            // Display Milestone endDate
            if (thisRequirement.getDeadline() != null) {
                String end = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user),
                        DateFormat.SHORT, thisRequirement.getDeadline());
                calendarView.addEvent(end, CalendarEventList.EVENT_TYPES[17], thisRequirement);
            }
        }

        // Retrieve the dates in which a requirement has a start or end date
        HashMap<String, HashMap<String, Integer>> dayGroups = requirementList.queryRecordCount(db,
                UserUtils.getUserTimeZone(user));
        for (String type : dayGroups.keySet()) {
            if ("startdate".equals(type)) {
                HashMap<String, Integer> dayEvents = dayGroups.get(type);
                for (String thisDay : dayEvents.keySet()) {
                    calendarView.addEventCount(thisDay,
                            CalendarEventList.EVENT_TYPES[CalendarEventList.MILESTONE_START],
                            dayEvents.get(thisDay));
                }
            } else if ("enddate".equals(type)) {
                HashMap<String, Integer> dayEvents = dayGroups.get(type);
                for (String thisDay : dayEvents.keySet()) {
                    calendarView.addEventCount(thisDay,
                            CalendarEventList.EVENT_TYPES[CalendarEventList.MILESTONE_END],
                            dayEvents.get(thisDay));
                }
            }

        }

        // Retrieve assignments that meet the criteria
        AssignmentList assignmentList = new AssignmentList();
        assignmentList.setProjectId(project.getId());
        assignmentList.setOnlyIfRequirementOpen(true);
        assignmentList.setAlertRangeStart(startDate);
        assignmentList.setAlertRangeEnd(endDate);
        if ("pending".equals(filter)) {
            assignmentList.setIncompleteOnly(true);
        } else if ("completed".equals(filter)) {
            assignmentList.setClosedOnly(true);
        }

        // Display the user's assignments by due date
        assignmentList.buildList(db);
        for (Assignment thisAssignment : assignmentList) {
            if (thisAssignment.getDueDate() != null) {
                String dueDate = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user),
                        DateFormat.SHORT, thisAssignment.getDueDate());
                calendarView.addEvent(dueDate, CalendarEventList.EVENT_TYPES[8], thisAssignment);
            }
        }

        // Retrieve the dates in which an assignment has a due date
        HashMap<String, Integer> dayEvents = assignmentList.queryAssignmentRecordCount(db,
                UserUtils.getUserTimeZone(user));
        for (String thisDay : dayEvents.keySet()) {
            calendarView.addEventCount(thisDay, CalendarEventList.EVENT_TYPES[CalendarEventList.ASSIGNMENT],
                    dayEvents.get(thisDay));
        }
    }

    if (ProjectUtils.hasAccess(project.getId(), user, "project-calendar-view")) {
        MeetingList meetingList = new MeetingList();
        meetingList.setProjectId(project.getId());
        meetingList.setEventSpanStart(startDate);
        if (!calendarInfo.isAgendaView()) {
            // limit the events to the date range chosen
            meetingList.setEventSpanEnd(endDate);
        }
        meetingList.setBuildAttendees(true);
        meetingList.buildList(db);
        LOG.debug("Meeting count = " + meetingList.size());
        // Display the meetings by date
        for (Meeting thisMeeting : meetingList) {
            if (thisMeeting.getStartDate() != null) {
                String start = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user),
                        DateFormat.SHORT, thisMeeting.getStartDate());
                if ("pending".equals(filter)) {
                    if (thisMeeting.getStartDate().getTime() > System.currentTimeMillis()) {
                        calendarView.addEvent(start, CalendarEventList.EVENT_TYPES[CalendarEventList.EVENT],
                                thisMeeting);
                    }
                } else if ("completed".equals(filter)) {
                    if (thisMeeting.getEndDate().getTime() < System.currentTimeMillis()) {
                        calendarView.addEvent(start, CalendarEventList.EVENT_TYPES[CalendarEventList.EVENT],
                                thisMeeting);
                    }
                } else {
                    if (calendarInfo.isAgendaView()) {
                        // Display meetings that started before today, but last greater than today, on the startDate of the calendar display
                        if (thisMeeting.getStartDate().before(startDate)) {
                            start = DateUtils.getServerToUserDateString(UserUtils.getUserTimeZone(user),
                                    DateFormat.SHORT, startDate);
                        }
                    }
                    calendarView.addEvent(start, CalendarEventList.EVENT_TYPES[CalendarEventList.EVENT],
                            thisMeeting);
                }
                LOG.debug("Meeting added for date: " + start);
            }
        }

        // Retrieve the dates for meeting events
        HashMap<String, Integer> dayEvents = meetingList.queryRecordCount(db, UserUtils.getUserTimeZone(user));
        for (String thisDay : dayEvents.keySet()) {
            LOG.debug("addingCount: " + thisDay + " = " + dayEvents.get(thisDay));
            calendarView.addEventCount(thisDay, CalendarEventList.EVENT_TYPES[CalendarEventList.EVENT],
                    dayEvents.get(thisDay));
        }
    }
    return calendarView;
}

From source file:fr.paris.lutece.plugins.workflow.modules.rest.service.formatters.WorkflowFormatterXml.java

/**
 * Format the workflow/*  w ww . ja va  2s .c o  m*/
 * @param sbXml the XML
 * @param workflow the workflow
 */
private void formatWorkflow(StringBuffer sbXml, Workflow workflow) {
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, I18nService.getDefaultLocale());
    String strDate = dateFormat.format(workflow.getCreationDate());

    XmlUtil.beginElement(sbXml, WorkflowRestConstants.TAG_WORKFLOW);

    XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_ID_WORKFLOW, workflow.getId());
    XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_NAME, workflow.getName());
    XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_DESCRIPTION, workflow.getDescription());
    XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_CREATION_DATE, strDate);
    XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_IS_ENABLE, Boolean.toString(workflow.isEnabled()));
    XmlUtil.addElement(sbXml, WorkflowRestConstants.TAG_WORKGROUP_KEY, workflow.getWorkgroup());

    XmlUtil.endElement(sbXml, WorkflowRestConstants.TAG_WORKFLOW);
}

From source file:org.apache.sqoop.shell.ShowLinkFunction.java

private void displayLink(MLink link) {
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

    printlnResource(Constants.RES_SHOW_PROMPT_LINK_INFO, link.getPersistenceId(), link.getName(),
            link.getEnabled(), link.getCreationUser(), formatter.format(link.getCreationDate()),
            link.getLastUpdateUser(), formatter.format(link.getLastUpdateDate()));

    long connectorId = link.getConnectorId();
    printlnResource(Constants.RES_SHOW_PROMPT_LINK_CID_INFO, connectorId);

    // Display link config
    displayConfig(link.getConnectorLinkConfig().getConfigs(), client.getConnectorConfigBundle(connectorId));
}

From source file:op.tools.SYSCalendar.java

public static ListCellRenderer getTimeRenderer() {
    return new ListCellRenderer() {
        DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);

        @Override//from   ww  w.  ja  va2s. c o  m
        public Component getListCellRendererComponent(JList jList, Object o, int i, boolean isSelected,
                boolean cellHasFocus) {
            String text;
            if (o == null) {
                text = SYSTools.xx("misc.commands.>>noselection<<");
            } else if (o instanceof Date) {
                Date date = (Date) o;
                text = timeFormat.format(date) + " " + SYSTools.xx("misc.msg.Time.short");
            } else {
                text = o.toString();
            }
            return new DefaultListCellRenderer().getListCellRendererComponent(jList, text, i, isSelected,
                    cellHasFocus);
        }
    };
}

From source file:action.OnlineBookingAction.java

@Actions({
        @Action(value = "/mobile", results = {
                @Result(name = "success", location = "/WEB-INF/jsp/online/widget1.jsp"),
                @Result(name = "input", location = "/WEB-INF/jsp/online/validationError.jsp") }),
        @Action(value = "/goOnlineBookingCalendar", results = {
                @Result(name = "success", location = "/WEB-INF/jsp/online/widget1.jsp"),
                @Result(name = "input", location = "/WEB-INF/jsp/online/validationError.jsp") }) })
public String goOnlineBookingCalendar() {
    Booking booking = null;// www  . j  a v a2 s. c  om
    Structure structure = null;
    Locale locale = null;
    SimpleDateFormat sdf = null;
    String datePattern = null;
    locale = this.getLocale();
    sdf = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale);
    datePattern = sdf.toPattern();
    this.getSession().put("datePattern", datePattern);
    structure = this.getStructureService().findStructureById(this.getIdStructure());
    this.setStructure(structure);

    booking = new Booking();
    booking.setStatus("online");
    booking.setId_structure(structure.getId());
    this.getSession().put("onlineBooking", booking);
    this.getSession().put("structure", structure);
    this.setBooking(booking);
    return SUCCESS;
}

From source file:net.nosleep.superanalyzer.analysis.views.TimeView.java

private void refreshDataset() {
    _dataset.clear();//from  w ww  .  ja v a  2s . c  o  m

    Stat itemStats = null;

    if (_comboBox == null) {
        itemStats = _analysis.getStats(Analysis.KIND_TRACK, null);
    } else {
        ComboItem item = (ComboItem) _comboBox.getSelectedItem();
        itemStats = _analysis.getStats(item.getKind(), item.getValue());
    }

    int[] hours = itemStats.getHours();
    for (int i = 0; i < 24; i++) {

        Calendar c = Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, i);
        c.set(Calendar.MINUTE, 0);

        SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT);

        _dataset.addValue(hours[i], Misc.getString("LISTENING_TIMES"), formatter.format(c.getTime()));
    }

    CategoryPlot plot = (CategoryPlot) _chart.getPlot();
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();

    axis.setAutoRangeStickyZero(false);

}

From source file:org.occupycincy.android.OccupyCincyActivity.java

private void processFeed() {

    feedItems = new ArrayList<HashMap<String, String>>();

    // default to Never
    String lastUpdated = getString(R.string.last_updated_never);

    File file = new File(getFullPath(getString(R.string.occupy_feed_file)));
    if (file.exists()) {
        parseOccupyFeed();// www.ja  va  2 s.co  m
        lastUpdated = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT)
                .format(new Date(file.lastModified()));
    }

    populateBlogView();

    // display Last Updated: 
    TextView txtLastUpdated = (TextView) findViewById(R.id.txtLastUpdated);
    txtLastUpdated.setText(getString(R.string.last_updated).replace("%TIME%", lastUpdated));

    setLoading(false);
}