Example usage for java.text DateFormat getDateInstance

List of usage examples for java.text DateFormat getDateInstance

Introduction

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

Prototype

public static final DateFormat getDateInstance() 

Source Link

Document

Gets the date formatter with the default formatting style for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:org.onebusaway.nyc.webapp.actions.wiki.IndexAction.java

public String getLastModifiedTimestamp() {
    if (lastModifiedTimestamp == null)
        return "Unknown";

    return DateFormat.getDateInstance().format(lastModifiedTimestamp) + " at "
            + DateFormat.getTimeInstance().format(lastModifiedTimestamp);
}

From source file:de.awtools.config.PropertiesGlueConfig.java

public void save() throws IOException {
    Date date = new Date();
    String tmp = DateFormat.getDateInstance().format(date);

    if (propertiesResource.getProtocol().equals("file")) {
        File outfile = new File(propertiesResource.getFile());
        OutputStream out = null;//w w  w.  j ava2  s.c  om
        try {
            out = new FileOutputStream(outfile);
            properties.store(out, "Saved on: " + tmp);
        } finally {
            IOUtils.closeQuietly(out);
        }
    } else {
        throw new IllegalStateException("Unsupported URL protocol: " + propertiesResource.getProtocol());
    }
}

From source file:com.eryansky.common.utils.DateUtil.java

/**
 * date1?date2?date1date2true date1date2?2009-08-01
 *//*from   w w  w  .j a  va  2  s.  c  o m*/
public static boolean isDate10Before(String date1, String date2) {
    try {
        DateFormat df = DateFormat.getDateInstance();
        return df.parse(date1).before(df.parse(date2));
    } catch (ParseException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:jp.terasoluna.batch.tutorial.sample000.SMP000BLogic.java

@Override
public int doMain(BLogicParam param) {

    int resultNum = 0;

    // DB???s??BftHg100?
    int maxNumber = 100;

    // ????e?[u???s??X
    if (null != param.getJobArgNm1()) {
        maxNumber = Integer.parseInt(param.getJobArgNm1());
    }/*from  w  w w.  j av a  2  s .c o  m*/

    // f?[^??p_?
    Random random = new Random();

    NyusyukkinData nyusyukkin = new NyusyukkinData();

    try {
        // ?oe?[uf?[^NA
        updateDAO.execute("SMP000.deleteNyusyukkin", null);

        for (int count = 1; count <= maxNumber; count++) {

            // _xX
            String shitenName = "";
            int shitenNum = random.nextInt(3) + 1;
            if (shitenNum == 1) {
                shitenName = "";
            } else if (shitenNum == 2) {
                shitenName = "?";
            } else if (shitenNum == 3) {
                shitenName = "?t";
            }
            String kokyakuId = String.valueOf(random.nextInt(1000) + 1);

            // pfBO(0)
            while (kokyakuId.length() < 4) {
                kokyakuId = "0" + kokyakuId;
            }
            int nyusyukkinKubun = random.nextInt(2);
            int kingaku = random.nextInt(1000000) + 1;

            // t(2010/01/01?`2011/12/31)_???B
            StringBuilder hiduke = new StringBuilder();
            hiduke.append(String.valueOf(2010 + random.nextInt(2)) + "/");
            int month = random.nextInt(12) + 1;
            hiduke.append(String.valueOf(month) + "/");
            if (month == 4 || month == 6 || month == 9 || month == 11) {
                hiduke.append(String.valueOf(random.nextInt(30) + 1));
            } else if (month == 2) {
                hiduke.append(String.valueOf(random.nextInt(28) + 1));
            } else {
                hiduke.append(String.valueOf(random.nextInt(31) + 1));
            }
            Date date = DateFormat.getDateInstance().parse(hiduke.toString());

            // P?sIuWFNg??
            nyusyukkin.setShitenName(shitenName);
            nyusyukkin.setKokyakuId(kokyakuId);
            nyusyukkin.setNyusyukkinKubun(nyusyukkinKubun);
            nyusyukkin.setKingaku(kingaku);
            nyusyukkin.setTorihikibi(date);

            // DBf?[^o^
            updateDAO.execute("SMP000.insertNyusyukkin", nyusyukkin);
        }

        if (log.isDebugEnabled()) {
            log.debug("end:NyusyukkinReset");
        }

    } catch (Exception e) {
        // O??(G?[R?[h?)
        resultNum = -1;
    }
    return resultNum;
}

From source file:com.madrobot.di.Converter.java

public static Object convertTo(final JSONObject jsonObject, final String fieldName, final Class<?> clz,
        final Field field) {

    Object value = null;/*from   w  w w. j ava  2  s .  c  om*/

    if (clzTypeKeyMap.containsKey(clz)) {
        try {
            final int code = clzTypeKeyMap.get(clz);
            switch (code) {
            case TYPE_STRING:
                value = jsonObject.optString(fieldName);
                break;
            case TYPE_SHORT:
                value = Short.parseShort(jsonObject.optString(fieldName, "0"));
                break;
            case TYPE_INT:
                value = jsonObject.optInt(fieldName);
                break;
            case TYPE_LONG:
                value = jsonObject.optLong(fieldName);
                break;
            case TYPE_CHAR:
                String chatValue = jsonObject.optString(fieldName);
                if (chatValue.length() > 0) {
                    value = chatValue.charAt(0);
                } else {
                    value = '\0';
                }
                break;
            case TYPE_FLOAT:
                value = Float.parseFloat(jsonObject.optString(fieldName, "0.0f"));
                break;
            case TYPE_DOUBLE:
                value = jsonObject.optDouble(fieldName);
                break;
            case TYPE_BOOLEAN:
                value = jsonObject.optString(fieldName);
                if (field.isAnnotationPresent(BooleanFormat.class)) {
                    BooleanFormat formatAnnotation = field.getAnnotation(BooleanFormat.class);
                    String trueFormat = formatAnnotation.trueFormat();
                    String falseFormat = formatAnnotation.falseFormat();
                    if (trueFormat.equals(value)) {
                        value = true;
                    } else if (falseFormat.equals(value)) {
                        value = false;
                    } else {
                        Log.e(JSONDeserializer.TAG,
                                "Expecting " + trueFormat + " / " + falseFormat + " but its " + value);
                    }
                } else {
                    value = Boolean.parseBoolean((String) value);
                }
                break;
            case TYPE_DATE:
                value = DateFormat.getDateInstance().parse(jsonObject.optString(fieldName));
                break;
            }
        } catch (NumberFormatException e) {
            Log.e(JSONDeserializer.TAG, e.getMessage());
        } catch (ParseException e) {
            Log.e(JSONDeserializer.TAG, e.getMessage());
        }
    }
    return value;
}

From source file:org.jamienicol.episodes.ShowDetailsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {

        int overviewColumnIndex = data.getColumnIndexOrThrow(ShowsTable.COLUMN_OVERVIEW);
        if (data.isNull(overviewColumnIndex)) {
            overviewView.setVisibility(View.GONE);
        } else {//  w  ww  .j  a  va 2  s  .c  o m
            overviewView.setText(data.getString(overviewColumnIndex).trim());
            overviewView.setVisibility(View.VISIBLE);
        }

        int firstAiredColumnIndex = data.getColumnIndexOrThrow(ShowsTable.COLUMN_FIRST_AIRED);
        if (data.isNull(firstAiredColumnIndex)) {
            firstAiredView.setVisibility(View.GONE);
        } else {
            Date firstAired = new Date(data.getLong(firstAiredColumnIndex) * 1000);
            DateFormat df = DateFormat.getDateInstance();
            String firstAiredText = getString(R.string.first_aired, df.format(firstAired));
            firstAiredView.setText(firstAiredText);
            firstAiredView.setVisibility(View.VISIBLE);
        }

    } else {
        overviewView.setVisibility(View.GONE);
        firstAiredView.setVisibility(View.GONE);
    }
}

From source file:com.alfaariss.oa.util.configuration.ConfigurationManager.java

/**
 * Saves the configuration./* www  .jav a  2 s.  c o m*/
 * @see IConfigurationManager#saveConfiguration()
 */
public synchronized void saveConfiguration() throws ConfigurationException {
    boolean bFound = false;
    Date dNow = null;
    StringBuffer sbComment = null;
    Element elRoot = null;
    Node nCurrent = null;
    Node nComment = null;
    String sValue = null;
    try {
        // add date to configuration
        dNow = new Date(System.currentTimeMillis());

        sbComment = new StringBuffer(" Configuration changes saved on ");
        sbComment.append(DateFormat.getDateInstance().format(dNow));
        sbComment.append(". ");

        elRoot = _oDomDocument.getDocumentElement();
        nCurrent = elRoot.getFirstChild();
        while (!bFound && nCurrent != null) // all elements
        {
            if (nCurrent.getNodeType() == Node.COMMENT_NODE) {
                // check if it's a "save changes" comment
                sValue = nCurrent.getNodeValue();
                if (sValue.trim().startsWith("Configuration changes saved on")) {
                    // overwrite message
                    nCurrent.setNodeValue(sbComment.toString());
                    bFound = true;
                }
            }
            nCurrent = nCurrent.getNextSibling();
        }
        if (!bFound) // no comment found: adding new
        {
            // create new comment node
            nComment = _oDomDocument.createComment(sbComment.toString());
            // insert comment before first node
            elRoot.insertBefore(nComment, elRoot.getFirstChild());
        }
        _oConfigHandler.saveConfiguration(_oDomDocument);
    } catch (ConfigurationException e) {
        throw e;
    } catch (Exception e) {
        _logger.fatal("Internal error", e);
        throw new ConfigurationException(SystemErrors.ERROR_INTERNAL);
    }
}

From source file:bbct.android.common.activity.MainActivity.java

private void showSurvey2Dialog() {
    DateFormat dateFormat = DateFormat.getDateInstance();
    Date today = new Date();
    final String todayStr = dateFormat.format(today);

    if (prefs.contains(SharedPreferenceKeys.SURVEY1_DATE)
            && !prefs.contains(SharedPreferenceKeys.SURVEY2_DATE)) {
        String survey1Date = prefs.getString(SharedPreferenceKeys.SURVEY1_DATE, today.toString());

        try {/*from ww w.  j  ava 2  s.  co m*/
            Calendar cal = Calendar.getInstance();
            cal.setTime(dateFormat.parse(survey1Date));
            cal.add(Calendar.DATE, SURVEY_DELAY);
            if (today.after(cal.getTime())) {
                DialogUtil.showSurveyDialog(this, todayStr, R.string.survey2, SharedPreferenceKeys.SURVEY2_DATE,
                        SURVEY2_URI);
            }
        } catch (ParseException e) {
            Log.d(TAG, "Error parsing install date");
            e.printStackTrace();
        }
    } else if (prefs.contains(SharedPreferenceKeys.SURVEY_TAKEN_PREF)) {
        prefs.edit().putString(SharedPreferenceKeys.SURVEY1_DATE, todayStr).apply();
    }
}

From source file:org.nuxeo.ecm.platform.jbpm.syndication.serializer.SimpleXMLSerializer.java

@Override
public void serialize(ResultSummary summary, List<DashBoardItem> workItems, String columnsDefinition,
        List<String> labels, String lang, Response res, HttpServletRequest req) {
    if (workItems == null) {
        return;/*from   ww  w  .j  a  v  a  2s  .c o m*/
    }

    QName tasksTag = DocumentFactory.getInstance().createQName(rootTaskNodeName, taskNSPrefix, taskNS);
    QName taskTag = DocumentFactory.getInstance().createQName(taskNodeName, taskNSPrefix, taskNS);
    QName taskCategoryTag = DocumentFactory.getInstance().createQName(taskCategoryNodeName, taskNSPrefix,
            taskNS);

    org.dom4j.Element rootElem = DocumentFactory.getInstance().createElement(tasksTag);
    rootElem.addNamespace(taskNSPrefix, taskNS);
    org.dom4j.Document rootDoc = DocumentFactory.getInstance().createDocument(rootElem);

    Map<String, List<DashBoardItem>> sortedDashBoardItem = new HashMap<String, List<DashBoardItem>>();
    for (DashBoardItem item : workItems) {
        String category = item.getDirective();
        if (category == null) {
            category = "None";
        }

        if (!sortedDashBoardItem.containsKey(category)) {
            sortedDashBoardItem.put(category, new ArrayList<DashBoardItem>());
        }
        sortedDashBoardItem.get(category).add(item);
    }

    for (String category : sortedDashBoardItem.keySet()) {
        org.dom4j.Element categoryElem = rootElem.addElement(taskCategoryTag);
        categoryElem.addAttribute("category", category);

        for (DashBoardItem item : sortedDashBoardItem.get(category)) {
            org.dom4j.Element taskElem = categoryElem.addElement(taskTag);
            taskElem.addAttribute("name", item.getName());
            taskElem.addAttribute("directive", item.getDirective());
            taskElem.addAttribute("description", item.getDescription());
            taskElem.addAttribute("id", item.getId().toString());
            taskElem.addAttribute("link", item.getDocumentLink());
            if (item.getDueDate() != null) {
                taskElem.addAttribute("dueDate", DateFormat.getDateInstance().format(item.getDueDate()));
            }
            if (item.getStartDate() != null) {
                taskElem.addAttribute("startDate", DateFormat.getDateInstance().format(item.getStartDate()));
            }
            String currentLifeCycle = "";

            try {
                currentLifeCycle = item.getDocument().getCurrentLifeCycleState();
            } catch (ClientException e) {
                log.debug("No LifeCycle found");
            }

            taskElem.addAttribute("currentDocumentLifeCycle", currentLifeCycle);

            // not thread-safe so don't use a static instance
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (item.getDueDate() != null) {
                taskElem.addAttribute("dueDate", dateFormat.format(item.getDueDate()));
            }
            if (item.getStartDate() != null) {
                taskElem.addAttribute("startDate", dateFormat.format(item.getStartDate()));
            }
            if (item.getComment() != null) {
                taskElem.setText(item.getComment());
            }
        }
    }
    QName translationTag = DocumentFactory.getInstance().createQName(translationNodeName, taskNSPrefix, taskNS);
    org.dom4j.Element translationElem = rootElem.addElement(translationTag);

    Map<String, String> translatedWords = getTranslationsForWorkflow("en");
    for (String key : translatedWords.keySet()) {
        translationElem.addAttribute(key, translatedWords.get(key));
    }

    res.setEntity(rootDoc.asXML(), MediaType.TEXT_XML);
    res.getEntity().setCharacterSet(CharacterSet.UTF_8);
}