Example usage for org.apache.commons.lang.time DateFormatUtils format

List of usage examples for org.apache.commons.lang.time DateFormatUtils format

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateFormatUtils format.

Prototype

public static String format(Date date, String pattern) 

Source Link

Document

Formats a date/time into a specific pattern.

Usage

From source file:net.shopxx.plugin.unionpayPayment.UnionpayPaymentPlugin.java

@Override
public boolean verifyNotify(PaymentPlugin.NotifyMethod notifyMethod, HttpServletRequest request) {

    Map<String, String> respParam = getAllRequestParam(request);
    String encoding = request.getParameter(SDKConstants.param_encoding);
    PluginConfig pluginConfig = getPluginConfig();
    PaymentLog paymentLog = getPaymentLog(request.getParameter("orderId"));

    Map<String, String> valideData = null;
    if (null != respParam && !respParam.isEmpty()) {
        Iterator<Entry<String, String>> it = respParam.entrySet().iterator();
        valideData = new HashMap<String, String>(respParam.size());
        while (it.hasNext()) {
            Entry<String, String> e = it.next();
            String key = (String) e.getKey();
            String value = (String) e.getValue();
            try {
                value = new String(value.getBytes(encoding), encoding);
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();//from   www.  j  a  v  a 2  s. c  o  m
            }
            valideData.put(key, value);
        }
    }
    if (!AcpService.validate(valideData, encoding)) {
        LogUtil.writeLog("???[].");
        return false;
    } else {
        LogUtil.writeLog("???[?].");
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("version", getVersion());
        parameterMap.put("encoding", getRequestCharset());
        parameterMap.put("signMethod", "01"); //?? ???01-RSA??
        parameterMap.put("txnType", "00"); // 00-
        parameterMap.put("txnSubType", "00"); //?  00
        parameterMap.put("bizType", "000201"); // B2Cwap

        parameterMap.put("merId", pluginConfig.getAttribute("partner"));
        parameterMap.put("accessType", "0"); //0?

        parameterMap.put("orderId", paymentLog.getSn());
        parameterMap.put("txnTime", DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"));

        Map<String, String> reqData = AcpService.sign(parameterMap, getRequestCharset());//certId,signaturesignData???????
        String url = SDKConfig.getConfig().getSingleQueryUrl();// url??acp_sdk.properties acpsdk.singleQueryUrl
        //signData?submitUrl??submitFromData??
        Map<String, String> rspData = AcpService.post(reqData, url, getRequestCharset());

        /**?????,???------------->**/
        //??open.unionpay.com   ??  ??-5-
        if (!rspData.isEmpty()) {
            if (AcpService.validate(rspData, getRequestCharset())) {
                LogUtil.writeLog("????");
                if ("00".equals(rspData.get("respCode"))) {//?
                    //??
                    String origRespCode = rspData.get("origRespCode");
                    if ("00".equals(origRespCode)) {
                        //???
                        return true;
                    } else if ("03".equals(origRespCode) || "04".equals(origRespCode)
                            || "05".equals(origRespCode)) {
                        //??? 
                        //TODO
                    } else {
                        //?
                        //TODO
                    }
                } else {//?
                        //TODO
                }
            } else {
                LogUtil.writeErrorLog("???");
                //TODO ???
            }
        } else {
            //http?
            LogUtil.writeErrorLog("?http???200");
            return false;
        }
    }

    return false;

    /*PluginConfig pluginConfig = getPluginConfig();
    PaymentLog paymentLog = getPaymentLog(request.getParameter("orderNumber"));
    if (paymentLog != null && generateSign(request.getParameterMap()).equals(request.getParameter("signature")) && pluginConfig.getAttribute("partner").equals(request.getParameter("merId")) && CURRENCY.equals(request.getParameter("orderCurrency"))
    && "00".equals(request.getParameter("respCode")) && paymentLog.getAmount().multiply(new BigDecimal(100)).compareTo(new BigDecimal(request.getParameter("orderAmount"))) == 0) {
       Map<String, Object> parameterMap = new HashMap<String, Object>();
       parameterMap.put("version", "1.0.0");
       parameterMap.put("charset", "UTF-8");
       parameterMap.put("transType", "01");
       parameterMap.put("merId", pluginConfig.getAttribute("partner"));
       parameterMap.put("orderNumber", paymentLog.getSn());
       parameterMap.put("orderTime", DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"));
       parameterMap.put("merReserved", "");
       parameterMap.put("signMethod", "MD5");
       parameterMap.put("signature", generateSign(parameterMap));
       String result = WebUtils.post("https://query.unionpaysecure.com/api/Query.action", parameterMap);
       if (ArrayUtils.contains(StringUtils.split(result, "&"), "respCode=00")) {
    return true;
       }
    }
    return false;*/
}

From source file:net.opentsdb.core.TsdbQuery.java

private void selectEndRows(List<KeyValue> oneList, Vector<String[]> vector, DataType dataType) {
    final long base_time = (end_time - (end_time % Const.MAX_TIMESPAN));
    short endMinAndSec = (short) (end_time - base_time);
    int myBaseTime = 0;
    for (int i = 0; i < oneList.size(); i++) {
        KeyValue kv = oneList.get(i);
        if (i == 0) {
            myBaseTime = (int) Bytes.getUnsignedInt(kv.key(), tsdb.metrics.width());
        }// w w  w  . j a v  a  2  s  .  co m
        short myMinAndSec = (short) (Bytes.getShort(kv.qualifier()) >> Const.FLAG_BITS);
        //?????,???
        if (myBaseTime < base_time || (myBaseTime == base_time && myMinAndSec <= endMinAndSec)) {
            String[] strArray = new String[] { dataType.getData(kv.value()),
                    DateFormatUtils.format(new Date(
                            (Bytes.getUnsignedInt(kv.key(), tsdb.metrics.width()) + myMinAndSec) * 1000),
                            DATE_PATTERN) };
            vector.add(strArray);
        }
    }
}

From source file:gov.nasa.ensemble.common.ui.type.editor.TimestampedNoteEditor.java

private void setDateTextInField(Text field, Date date) {
    if (date == null) {
        field.setText("");
    } else {//  w  ww .  j  a v  a  2  s  .co  m
        field.setText(DateFormatUtils.format(date, "MM/dd/yyyy hh:mm:ss"));
    }
}

From source file:gemlite.core.internal.support.jpa.files.dao.GmBatchDaoImpl.java

private String format(Date dt, String fmtStr) {
    if (dt == null)
        return "";
    String str = DateFormatUtils.format(dt, fmtStr);
    return str;//from  w w w  .j av a 2  s  .c om
}

From source file:com.littlehotspot.hadoop.mr.nginx.module.cdf.CDFMapper.java

private String turnDateFormat(String srcDateString) throws ParseException {
    String dateString = this.turnDataForNone(srcDateString);
    if (StringUtils.isBlank(dateString)) {
        return "";
    }// www . j  a  v  a  2s  .com
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constant.DATA_FORMAT_1, Locale.US);
    Date date = simpleDateFormat.parse(dateString);
    String tarDateString = DateFormatUtils.format(date, Constant.DATA_FORMAT_2);
    return tarDateString;
}

From source file:cn.ipanel.apps.portalBackOffice.util.CommonsFiend.java

public static String getCurrentTime() {
    return DateFormatUtils.format(Calendar.getInstance().getTime(), Defines.FORMAT_TIME_STRING);
}

From source file:net.sourceforge.fenixedu.presentationTier.TagLib.sop.examsMapNew.renderers.ExamsMapContentRenderer.java

@Override
public StringBuilder renderDayContents(ExamsMapSlot examsMapSlot, Integer year1, Integer year2, String typeUser,
        PageContext pageContext) {/*from   w  w w  . j a  va2  s  . co m*/
    StringBuilder strBuffer = new StringBuilder();

    for (int i = 0; i < examsMapSlot.getExams().size(); i++) {
        InfoExam infoExam = (InfoExam) examsMapSlot.getExams().get(i);
        Integer curicularYear = infoExam.getInfoExecutionCourse().getCurricularYear();

        if (curicularYear.equals(year1) || curicularYear.equals(year2)) {
            boolean isOnValidWeekDay = onValidWeekDay(infoExam);

            InfoExecutionCourse infoExecutionCourse = infoExam.getInfoExecutionCourse();
            String courseInitials = infoExam.getInfoExecutionCourse().getSigla();

            if (typeUser.equals("sop")) {
                strBuffer.append("<a href='showExamsManagement.do?method=edit&amp;"
                        + PresentationConstants.EXECUTION_COURSE_OID + "=" + infoExecutionCourse.getExternalId()
                        + "&amp;" + PresentationConstants.EXECUTION_PERIOD_OID + "="
                        + infoExecutionCourse.getInfoExecutionPeriod().getExternalId() + "&amp;"
                        + PresentationConstants.EXECUTION_DEGREE_OID + "="
                        + examsMap.getInfoExecutionDegree().getExternalId() + "&amp;"
                        + PresentationConstants.CURRICULAR_YEAR_OID + "=" + curicularYear.toString() + "&amp;"
                        + PresentationConstants.EXAM_OID + "=" + infoExam.getExternalId() + "'>");
                if (isOnValidWeekDay) {
                    strBuffer.append(courseInitials);
                } else {
                    strBuffer.append("<span class='redtxt'>" + courseInitials + "</span>");
                }

            } else if (typeUser.equals("public")) {

                final Site site = infoExecutionCourse.getExecutionCourse().getSite();
                strBuffer.append(GenericChecksumRewriter.NO_CHECKSUM_PREFIX);
                strBuffer.append("<a href=\"")
                        .append(((HttpServletRequest) pageContext.getRequest()).getContextPath());
                strBuffer.append(site.getReversePath());
                strBuffer.append("\">");
                strBuffer.append(courseInitials);
            }

            strBuffer.append("</a>");
            if (infoExam.getBeginning() != null) {
                boolean isAtValidHour = atValidHour(infoExam);
                String hoursText = infoExam.getBeginning().get(Calendar.HOUR_OF_DAY) + "h"
                        + DateFormatUtils.format(infoExam.getBeginning().getTime(), "mm");
                strBuffer.append(" ");
                strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.as"));
                strBuffer.append(" ");

                if (isAtValidHour || !typeUser.equals("sop")) {
                    strBuffer.append(hoursText);
                } else {
                    strBuffer.append("<span class='redtxt'>" + hoursText + "</span>");
                }
            }

            strBuffer.append("<br />");
        }
    }

    strBuffer.append("<br />");

    return strBuffer;
}

From source file:hubert.team.paragraphs.AdvertsOverviewModel.java

public String getMonth() {
    return DateFormatUtils.format(minDate, "MMMM");
}

From source file:cn.ipanel.apps.portalBackOffice.util.CommonsFiend.java

public static String next59Secends(String beginTime) {
    Date begin = new Date();
    try {/*ww  w.  jav a 2  s. c om*/
        begin = new SimpleDateFormat(Defines.FORMAT_TIME_STRING).parse(beginTime);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    long nextMinute = begin.getTime() + 59000;
    return DateFormatUtils.format(nextMinute, Defines.FORMAT_TIME_STRING);
}

From source file:net.opentsdb.core.TsdbQuery.java

private void selectStartRows(List<KeyValue> oneList, Vector<String[]> vector, DataType dataType) {
    final int base_time = (start_time - (start_time % Const.MAX_TIMESPAN));
    short startMinAndSec = (short) (start_time - base_time);
    int myBaseTime = 0;
    for (int i = 0; i < oneList.size(); i++) {
        KeyValue kv = oneList.get(i);
        if (i == 0) {
            myBaseTime = (int) Bytes.getUnsignedInt(kv.key(), tsdb.metrics.width());
        }/*from  w  w  w  . j a va  2 s  .c om*/
        short myMinAndSec = (short) (Bytes.getShort(kv.qualifier()) >> Const.FLAG_BITS);
        //????,???
        if (myBaseTime > base_time || (myBaseTime == base_time && myMinAndSec >= startMinAndSec)) {
            String[] strArray = new String[] { dataType.getData(kv.value()),
                    DateFormatUtils.format(new Date(
                            (Bytes.getUnsignedInt(kv.key(), tsdb.metrics.width()) + myMinAndSec) * 1000),
                            DATE_PATTERN) };
            vector.add(strArray);
        }
    }
}