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:org.apache.sqoop.shell.ShowJobFunction.java

private void displayJob(MJob job) {
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

    printlnResource(Constants.RES_SHOW_PROMPT_JOB_INFO, job.getPersistenceId(), job.getName(), job.getEnabled(),
            job.getCreationUser(), formatter.format(job.getCreationDate()), job.getLastUpdateUser(),
            formatter.format(job.getLastUpdateDate()));
    printlnResource(Constants.RES_SHOW_PROMPT_JOB_LID_CID_INFO, job.getLinkId(Direction.FROM),
            job.getConnectorId(Direction.FROM));

    displayConfig(job.getJobConfig(Direction.FROM).getConfigs(),
            client.getConnectorConfigBundle(job.getConnectorId(Direction.FROM)));
    displayConfig(job.getDriverConfig().getConfigs(), client.getDriverConfigBundle());
    displayConfig(job.getJobConfig(Direction.TO).getConfigs(),
            client.getConnectorConfigBundle(job.getConnectorId(Direction.TO)));
}

From source file:org.totschnig.myexpenses.dialog.ExportDialogFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from  w  ww .j  a va  2s.c o  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Activity ctx = (Activity) getActivity();
    Context wrappedCtx = DialogUtils.wrapContext1(ctx);
    Bundle args = getArguments();
    Long accountId = args != null ? args.getLong("accountId") : null;
    boolean allP = false;
    String warningText;
    if (accountId == null) {
        allP = true;
        warningText = getString(R.string.warning_reset_account_all);
    } else if (accountId < 0L) {
        allP = true;
        AggregateAccount aa = AggregateAccount.getCachedInstance(accountId);
        if (aa == null)
            throw new DataObjectNotFoundException(accountId);
        warningText = getString(R.string.warning_reset_account_all, " (" + aa.currency.getCurrencyCode() + ")");
    } else {
        warningText = getString(R.string.warning_reset_account);
    }
    LayoutInflater li = LayoutInflater.from(wrappedCtx);
    View view = li.inflate(R.layout.export_dialog, null);
    dateFormatET = (EditText) view.findViewById(R.id.date_format);
    String dateFormatDefault = ((SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT)).toPattern();
    String dateFormat = MyApplication.getInstance().getSettings().getString(PREFKEY_EXPORT_DATE_FORMAT, "");
    if (dateFormat.equals(""))
        dateFormat = dateFormatDefault;
    else {
        try {
            new SimpleDateFormat(dateFormat, Locale.US);
        } catch (IllegalArgumentException e) {
            dateFormat = dateFormatDefault;
        }
    }
    dateFormatET.setText(dateFormat);
    dateFormatET.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            try {
                new SimpleDateFormat(s.toString(), Locale.US);
                mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
            } catch (IllegalArgumentException e) {
                dateFormatET.setError(getString(R.string.date_format_illegal));
                mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    notYetExportedCB = (CheckBox) view.findViewById(R.id.export_not_yet_exported);
    deleteCB = (CheckBox) view.findViewById(R.id.export_delete);
    warningTV = (TextView) view.findViewById(R.id.warning_reset);
    formatRB = (RadioButton) view.findViewById(R.id.csv);
    String format = MyApplication.getInstance().getSettings().getString(MyApplication.PREFKEY_EXPORT_FORMAT,
            "QIF");
    boolean deleteP = true;
    if (format.equals("CSV"))
        (formatRB).setChecked(true);
    deleteCB.setOnClickListener(this);
    if (Account.getHasExported(accountId)) {
        deleteP = false;
        deleteCB.setChecked(false);
        notYetExportedCB.setChecked(true);
        notYetExportedCB.setVisibility(View.VISIBLE);
    }
    warningTV.setText(warningText);
    if (deleteP)
        warningTV.setVisibility(View.VISIBLE);
    else
        warningTV.setVisibility(View.GONE);
    AlertDialog.Builder builder = new AlertDialog.Builder(wrappedCtx)
            .setTitle(allP ? R.string.menu_reset_all : R.string.menu_reset).setView(view)
            .setPositiveButton(android.R.string.ok, this).setNegativeButton(android.R.string.cancel, null);
    if (Build.VERSION.SDK_INT < 11)
        builder.setIcon(android.R.drawable.ic_dialog_alert);
    else
        builder.setIconAttribute(android.R.attr.alertDialogIcon);
    mDialog = builder.create();
    return mDialog;
}

From source file:es.warp.killthedj.track.AvailableTrack.java

public String getDuration() {
    // TODO library like duration from ruby
    return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(getTime());
}

From source file:org.mifos.framework.util.helpers.DateUtils.java

public static String getUserLocaleDate(Locale locale, Date databaseDate) {
    // the following line is for 1.1 release and will be removed when date
    // is localized
    locale = internalLocale;//from   w  ww .  ja  v  a 2  s.c  om
    SimpleDateFormat shortFormat = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale);
    return shortFormat.format(databaseDate);
}

From source file:com.projity.util.DateTime.java

public static DateFormat utcShortDateFormatInstance() {
    DateFormat f = DateFormat.getDateInstance(DateFormat.SHORT);
    f.setTimeZone(DateUtils.UTC_TIME_ZONE);
    return f;//from ww w . j  a va2s .  co  m
}

From source file:io.github.grahambell.taco.ServerTest.java

@Test
public void testServerViaXP() throws TacoException {
    DummyTransport xp = (DummyTransport) this.xp;

    // We should be starting with an empty object cache.
    assertEquals(objects.size(), 0);//from   w w w . j  a v a2s.c  o m
    assertEquals(objectNum, 0);

    // Try to construct a Date object.
    xp.setResponse(new JSONObject().put("action", "construct_object").put("class", "java.util.Date")
            .put("args", new JSONArray(new int[] { 115, 3, 1 })).put("kwargs", JSONObject.NULL), true);

    run();

    assertThat(xp.getMessage(), matchesJson(
            new JSONObject().put("action", "result").put("result", new JSONObject().put("_Taco_Object_", 1))));

    assertEquals(objects.size(), 1);
    assertEquals(objectNum, 1);
    assertTrue(objects.get(1) instanceof java.util.Date);

    // Try the Data object's methods.
    xp.setResponse(new JSONObject().put("action", "call_method").put("name", "getYear").put("number", 1)
            .put("args", JSONObject.NULL).put("kwargs", JSONObject.NULL), true);

    run();

    assertThat(xp.getMessage(), matchesJson(new JSONObject().put("action", "result").put("result", 115)));

    xp.setResponse(new JSONObject().put("action", "call_method").put("name", "getMonth").put("number", 1)
            .put("args", JSONObject.NULL).put("kwargs", JSONObject.NULL), true);

    run();

    assertThat(xp.getMessage(), matchesJson(new JSONObject().put("action", "result").put("result", 3)));

    xp.setResponse(new JSONObject().put("action", "call_method").put("name", "getDate").put("number", 1)
            .put("args", JSONObject.NULL).put("kwargs", JSONObject.NULL), true);

    run();

    assertThat(xp.getMessage(), matchesJson(new JSONObject().put("action", "result").put("result", 1)));

    // Construct a Locale object.
    xp.setResponse(
            new JSONObject().put("action", "construct_object").put("class", "java.util.Locale")
                    .put("args", new JSONArray(new String[] { "en", "US" })).put("kwargs", JSONObject.NULL),
            true);

    run();

    assertThat(xp.getMessage(), matchesJson(
            new JSONObject().put("action", "result").put("result", new JSONObject().put("_Taco_Object_", 2))));

    assertEquals(objects.size(), 2);
    assertEquals(objectNum, 2);
    assertTrue(objects.get(2) instanceof java.util.Locale);

    // Get a DateFormat object.
    xp.setResponse(
            new JSONObject().put("action", "call_class_method").put("class", "java.text.DateFormat")
                    .put("name", "getDateInstance")
                    .put("args",
                            new JSONArray(new Object[] { new Integer(DateFormat.SHORT),
                                    new JSONObject().put("_Taco_Object_", 2) }))
                    .put("kwargs", JSONObject.NULL),
            true);

    run();

    assertThat(xp.getMessage(), matchesJson(
            new JSONObject().put("action", "result").put("result", new JSONObject().put("_Taco_Object_", 3))));

    assertEquals(objects.size(), 3);
    assertEquals(objectNum, 3);
    assertTrue(objects.get(3) instanceof java.text.DateFormat);

    // Finally, format the date.
    xp.setResponse(new JSONObject().put("action", "call_method").put("number", 3).put("name", "format")
            .put("args", new JSONArray(new Object[] { new JSONObject().put("_Taco_Object_", 1) }))
            .put("kwargs", JSONObject.NULL), true);

    run();

    assertThat(xp.getMessage(), matchesJson(new JSONObject().put("action", "result").put("result", "4/1/15")));

    // Destroy the objects.
    xp.setResponse(new JSONObject().put("action", "destroy_object").put("number", 3), true);

    run();

    assertEquals(objects.size(), 2);

    xp.setResponse(new JSONObject().put("action", "destroy_object").put("number", 2), true);

    run();

    assertEquals(objects.size(), 1);
    assertTrue(objects.get(1) instanceof java.util.Date);

    xp.setResponse(new JSONObject().put("action", "destroy_object").put("number", 1), true);

    run();

    assertEquals(objects.size(), 0);

    // Counter should not have been reset.
    assertEquals(objectNum, 3);

    xp.setResponse(new JSONObject().put("action", "construct_object").put("class", "java.util.Date")
            .put("args", JSONObject.NULL).put("kwargs", JSONObject.NULL), true);

    run();

    assertThat(xp.getMessage(), matchesJson(
            new JSONObject().put("action", "result").put("result", new JSONObject().put("_Taco_Object_", 4))));

    assertEquals(objectNum, 4);
    assertEquals(objects.size(), 1);

    // Test class attribute actions.
    xp.setResponse(new JSONObject().put("action", "get_class_attribute")
            .put("class", "io.github.grahambell.taco.ExampleClass").put("name", "attr_one"), true);

    run();

    assertThat(xp.getMessage(), matchesJson(new JSONObject().put("action", "result").put("result", 5678)));

    xp.setResponse(new JSONObject().put("action", "set_class_attribute")
            .put("class", "io.github.grahambell.taco.ExampleClass").put("name", "attr_one").put("value", 8765),
            true);

    run();

    assertThat(xp.getMessage(),
            matchesJson(new JSONObject().put("action", "result").put("result", JSONObject.NULL)));

    assertEquals(8765, ExampleClass.attr_one);
}

From source file:org.jactr.eclipse.runtime.launching.env.EnvironmentConfigurator.java

static public IFile createRuntimeEnvironmentFile(ILaunchConfiguration config, String mode,
        IProgressMonitor monitor) throws CoreException {
    /*/*from  www.ja v  a  2 s  .c  o  m*/
     * make sure we have runs/
     */
    IFile configurationFile = null;
    IProject project = ACTRLaunchConfigurationUtils.getProject(config);

    if (config.getAttribute(ACTRLaunchConstants.ATTR_SAVE_RUN, true)) {
        IFolder runtimeFolder = project.getFolder("runs");

        if (!runtimeFolder.exists())
            runtimeFolder.create(true, true, monitor);

        /*
         * create {now}
         */
        Date now = new Date();
        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
        String name = df.format(now);
        name = name.replace("/", ".");
        IFolder thisRun = runtimeFolder.getFolder(name);

        if (!thisRun.exists())
            thisRun.create(true, true, monitor);

        df = DateFormat.getTimeInstance(DateFormat.MEDIUM);
        name = df.format(now).replace(":", ".").replace(" ", "");
        thisRun = thisRun.getFolder(name);

        if (!thisRun.exists())
            thisRun.create(true, true, monitor);

        configurationFile = thisRun.getFile("environment.xml");
    } else {
        // tmp directory and temp file
        IPath workingLocation = project.getWorkingLocation(RuntimePlugin.PLUGIN_ID);
        workingLocation.append("/tmp/");
        IFolder tmpLocation = project.getFolder(workingLocation);
        tmpLocation.create(true, true, monitor);
        // TODO this could screw up if you try to run multiple instances at once
        configurationFile = tmpLocation.getFile(project.getName() + "-environment.xml");
    }

    return configurationFile;
}

From source file:net.alexjf.tmm.fragments.ImmedTransactionEditorFragment.java

public ImmedTransactionEditorFragment() {
    dateFormat = DateFormat.getDateInstance();
    timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
}

From source file:liquibase.lockservice.LockServiceEx.java

/**
 * Wait for lock./* w  ww  .j  a  va 2s.c  om*/
 * 
 * @throws LockException
 *             occurs when lock manipulation is failed.
 */
public void waitForLock() throws LockException {

    boolean locked = false;
    long timeToGiveUp = new Date().getTime() + changeLogLockWaitTime;
    while (!locked && new Date().getTime() < timeToGiveUp) {
        locked = acquireLock();
        if (!locked) {
            LOGGER.info("Waiting for changelog lock....");
            try {
                Thread.sleep(changeLogLocRecheckTime);
            } catch (InterruptedException e) {
                noOp();
            }
        }
    }

    if (!locked) {
        DatabaseChangeLogLock[] locks = listLocks();
        String lockedBy;
        if (locks.length > 0) {
            DatabaseChangeLogLock lock = locks[0];
            lockedBy = lock.getLockedBy() + " since " + DateFormat
                    .getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(lock.getLockGranted());
        } else {
            lockedBy = "UNKNOWN";
        }
        throw new LockException("Could not acquire change log lock.  Currently locked by " + lockedBy);
    }
}

From source file:com.sfs.whichdoctor.dao.ItemDAOImpl.java

/**
 * Used to get a TreeMap of ItemBean details for a specified GUID number.
 *
 * @param guid the guid/* w w  w. j  av  a2 s  . c  om*/
 * @param fullResults the full results
 * @param itemTypeVal the item type value
 * @param groupClassVal the group class value
 * @param object2GUID the object2 guid
 * @param startDate the start date
 * @param endDate the end date
 *
 * @return the tree map< string, item bean>
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final TreeMap<String, ItemBean> load(final int guid, final boolean fullResults, final String itemTypeVal,
        final String groupClassVal, final int object2GUID, final String startDate, final String endDate)
        throws WhichDoctorDaoException {

    TreeMap<String, ItemBean> items = new TreeMap<String, ItemBean>();

    String itemType = "Group";
    String groupClass = "Members";
    if (itemTypeVal != null) {
        itemType = itemTypeVal;
    }
    if (groupClass != null) {
        groupClass = groupClassVal;
    }

    if (StringUtils.equalsIgnoreCase(itemType, "Employer")
            || StringUtils.equalsIgnoreCase(itemType, "Employee")) {
        itemType = "Employment";
    }

    java.util.Date dtStartDate = null;
    java.util.Date dtEndDate = null;
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK);
    try {
        dtStartDate = df.parse(startDate);
    } catch (Exception e) {
        dataLogger.debug("Error parsing start date: " + e.getMessage());
    }
    try {
        dtEndDate = df.parse(endDate);
    } catch (Exception e) {
        dataLogger.debug("Error parsing end date: " + e.getMessage());
    }
    if (dtStartDate != null && dtEndDate != null && dtStartDate.compareTo(dtEndDate) > 0) {
        /* Start date is greater than end date, switch around */
        java.util.Date tempStartDate = dtStartDate;
        dtStartDate = dtEndDate;
        dtEndDate = tempStartDate;
    }

    StringBuffer loadItems = new StringBuffer();
    ArrayList<Object> parameters = new ArrayList<Object>();
    parameters.add(guid);
    parameters.add(itemType);

    loadItems.append(getLoadSQL(groupClass));

    if (StringUtils.equalsIgnoreCase(groupClass, "Employers")) {
        loadItems.append(" AND items.Object2GUID = ? AND itemtype.Class = ?");
    } else {
        loadItems.append(" AND items.Object1GUID = ? AND itemtype.Class = ?");
    }
    if (object2GUID > 0) {
        loadItems.append(" AND items.Object2GUID = ?");
        parameters.add(object2GUID);
    }

    dataLogger.info("Items for GUID: " + guid + " requested");

    Collection<ItemBean> itemCollection = new ArrayList<ItemBean>();
    try {
        itemCollection = this.getJdbcTemplateReader().query(loadItems.toString(), parameters.toArray(),
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadItem(rs);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for this search: " + ie.getMessage());
    }

    for (ItemBean item : itemCollection) {
        if (item.display(dtStartDate, dtEndDate)) {
            items.put(item.getOrderIndex(), item);
        }
    }

    return items;
}