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:MainClass.java

public static void main(String[] args) {

    //Format milliseconds in long
    System.out.println(//ww  w  .j ava 2s  .co  m
            "4) MMM dd yy HH:mm >>>" + DateFormatUtils.format(System.currentTimeMillis(), "MMM dd yy HH:mm"));

}

From source file:TimeTrial.java

public static void main(String[] args) {
    // Format Date into dd-MM-yyyy
    System.out.println("1) dd-MM-yyyy >>>" + DateFormatUtils.format(new Date(), "dd-MM-yyyy"));

    // Format Date into SMTP_DATETIME_FORMAT
    System.out.println("2) SMTP_DATETIME_FORMAT >>>" + DateFormatUtils.SMTP_DATETIME_FORMAT.format(new Date()));

    // Format Date into ISO_DATE_FORMAT
    System.out.println("3) ISO_DATE_FORMAT >>>" + DateFormatUtils.ISO_DATE_FORMAT.format(new Date()));

    // Format milliseconds in long
    System.out.println(/*  w ww.  j a v a2s  .c  om*/
            "4) MMM dd yy HH:mm >>>" + DateFormatUtils.format(System.currentTimeMillis(), "MMM dd yy HH:mm"));

    // Format milliseconds in long using UTC timezone
    System.out.println(
            "5) MM/dd/yy HH:mm >>>" + DateFormatUtils.formatUTC(System.currentTimeMillis(), "MM/dd/yy HH:mm"));
}

From source file:MainClass.java

public static void main(String[] pArgs) throws Exception {
    //Format Date into dd-MM-yyyy
    System.out.println("1) dd-MM-yyyy >>>" + DateFormatUtils.format(new Date(), "dd-MM-yyyy"));
}

From source file:com.lsq.httpclient.netpay.BasicInfo.java

public static void main(String[] args) throws Exception {
    //   final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("F://test/pkcs8_rsa_private_key_2048.pem", "pem", null, "RSA");
    //   final PublicKey yhPubKey = CryptoUtil.getRSAPublicKeyByFileSuffix("F://??/rsa_public_key_2048.pem", "pem", "RSA");
    ///*  w  ww  .ja  v a2s.c  om*/
    //   final String url = "http://localhost:8080/interfaceWeb/basicInfo";
    //   final String url = "https://testapp.sicpay.com:11008/interfaceWeb/basicInfo";   

    //?
    //   final String url = "http://120.31.132.120:8082/interfaceWeb/basicInfo";
    //       final PublicKey yhPubKey = CryptoUtil.getRSAPublicKeyByFileSuffix("C:\\document\\key\\000158120120\\GHT_ROOT.pem", "pem", "RSA");
    //        final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("C:\\document\\key\\000000153990021\\000000153990021.pem", "pem", null, "RSA");
    //   final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("C:/document/key/000000158120121/000000158120121.pem", "pem", null, "RSA");
    //   final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("D:/key/000000152110003.pem", "pem", null, "RSA");
    //   final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("D:/key/test_pkcs8_rsa_private_key_2048.pem", "pem", null, "RSA");
    //   PublicKey yhPubKey = TestUtil.getPublicKey();
    //   PrivateKey hzfPriKey = TestUtil.getPrivateKey();

    //    final String url = "http://epay.gaohuitong.com:8083/interfaceWeb/basicInfo";

    //        final String url = "http://gpay.gaohuitong.com:8086/interfaceWeb2/basicInfo";
    //       final PublicKey yhPubKey = CryptoUtil.getRSAPublicKeyByFileSuffix("C:/document/key/549440155510001/GHT_ROOT.pem", "pem", "RSA");
    //    final PrivateKey hzfPriKey = CryptoUtil.getRSAPrivateKeyByFileSuffix("C:/document/key/549440155510001/549440155510001.pem", "pem", null, "RSA");

    //    final String url = "https://portal.sicpay.com:8087/interfaceWeb/basicInfo";

    final String url = TestUtil.interface_url + "basicInfo";

    final PublicKey yhPubKey = TestUtil.getPublicKey();
    final PrivateKey hzfPriKey = TestUtil.getPrivateKey();

    int i = 0;
    //   int j = 0;
    while (i < 1) {
        i++;
        try {
            HttpClient4Util httpClient4Util = new HttpClient4Util();
            StringBuilder sBuilder = new StringBuilder();
            sBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            sBuilder.append("<merchant>");
            sBuilder.append("<head>");
            sBuilder.append("<version>2.0.0</version>");
            //         sBuilder.append("<agencyId>549440155510001</agencyId>");
            sBuilder.append("<agencyId>" + TestUtil.merchantId + "</agencyId>");
            sBuilder.append("<msgType>01</msgType>");
            sBuilder.append("<tranCode>100001</tranCode>");
            sBuilder.append("<reqMsgId>" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + i + i
                    + "</reqMsgId>");
            sBuilder.append("<reqDate>" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + "</reqDate>");
            sBuilder.append("</head>");
            sBuilder.append("<body>");

            sBuilder.append("<handleType>0</handleType>");
            sBuilder.append("<merchantName>LIBTEST1</merchantName>");
            sBuilder.append("<shortName>UNCLE HENRY(A)</shortName>");
            sBuilder.append("<city>344344</city>");
            sBuilder.append(
                    "<merchantAddress>UNIT C 15/FHUA CHIAO COMM CTR 678 NATHAN RD MONGKOK KL</merchantAddress>");
            sBuilder.append("<servicePhone>13250538964</servicePhone>");
            sBuilder.append("<orgCode></orgCode>");
            sBuilder.append("<merchantType>01</merchantType>");
            sBuilder.append("<category>5399</category>");
            sBuilder.append("<corpmanName>?</corpmanName>");
            sBuilder.append("<corpmanId>440103198112214218</corpmanId>");
            sBuilder.append("<corpmanPhone>13926015921</corpmanPhone>");
            sBuilder.append("<corpmanMobile>13926015921</corpmanMobile>");
            sBuilder.append("<corpmanEmail>>zhanglibo@sicpay.com</corpmanEmail>");
            sBuilder.append("<bankCode>105</bankCode>");
            sBuilder.append("<bankName></bankName>");
            sBuilder.append("<bankaccountNo>6250502002603958</bankaccountNo>");
            sBuilder.append("<bankaccountName>?</bankaccountName>");
            sBuilder.append("<autoCus>0</autoCus>");
            sBuilder.append("<remark></remark>");
            sBuilder.append("<licenseNo>91440184355798892G</licenseNo>");
            //         sBuilder.append("<taxRegisterNo></taxRegisterNo>");
            //         sBuilder.append("<subMerchantNo></subMerchantNo>");
            //         sBuilder.append("<inviteMerNo></inviteMerNo>");
            //         sBuilder.append("<county></county>");
            //         sBuilder.append("<appid>wx04df48e919ef7b28</appid>");
            //         sBuilder.append("<pid>2015062600009243</pid>");
            //         sBuilder.append("<childEnter>1</childEnter>");
            //         sBuilder.append("<ghtEnter>0</ghtEnter>");
            //         sBuilder.append("<addrType>BUSINESS_ADDRESS</addrType>");
            //         sBuilder.append("<contactType>LEGAL_PERSON</contactType>");
            //         sBuilder.append("<mcc>200101110640354</mcc>");
            //         sBuilder.append("<licenseType>NATIONAL_LEGAL_MERGE</licenseType>");
            //         sBuilder.append("<authPayDir>http://epay.gaohuitong.com/channel/|http://test.pengjv.com/channel/</authPayDir>");
            //         sBuilder.append("<scribeAppid>wx04df48e919ef7b28</scribeAppid>");
            //         sBuilder.append("<contactMan></contactMan>");
            //         sBuilder.append("<telNo>18675857506</telNo>");
            //         sBuilder.append("<mobilePhone>18675857506</mobilePhone>");
            //         sBuilder.append("<email>CSC@sicpay.com</email>");
            //         sBuilder.append("<licenseBeginDate>20150826</licenseBeginDate>");
            //         sBuilder.append("<licenseEndDate>20991231</licenseEndDate>");
            //         sBuilder.append("<licenseRange>?????????????</licenseRange>");

            sBuilder.append("</body>");
            sBuilder.append("</merchant>");

            String plainXML = sBuilder.toString();
            byte[] plainBytes = plainXML.getBytes("UTF-8");
            String keyStr = "4D22R4846VFJ8HH4";
            byte[] keyBytes = keyStr.getBytes("UTF-8");
            byte[] base64EncryptDataBytes = Base64.encodeBase64(
                    CryptoUtil.AESEncrypt(plainBytes, keyBytes, "AES", "AES/ECB/PKCS5Padding", null));
            String encryptData = new String(base64EncryptDataBytes, "UTF-8");
            byte[] base64SingDataBytes = Base64
                    .encodeBase64(CryptoUtil.digitalSign(plainBytes, hzfPriKey, "SHA1WithRSA"));
            String signData = new String(base64SingDataBytes, "UTF-8");
            byte[] base64EncyrptKeyBytes = Base64
                    .encodeBase64(CryptoUtil.RSAEncrypt(keyBytes, yhPubKey, 2048, 11, "RSA/ECB/PKCS1Padding"));
            String encrtptKey = new String(base64EncyrptKeyBytes, "UTF-8");
            List<NameValuePair> nvps = new LinkedList<NameValuePair>();
            nvps.add(new BasicNameValuePair("encryptData", encryptData));
            nvps.add(new BasicNameValuePair("encryptKey", encrtptKey));
            //         nvps.add(new BasicNameValuePair("agencyId", "549440155510001"));
            nvps.add(new BasicNameValuePair("agencyId", TestUtil.merchantId));
            nvps.add(new BasicNameValuePair("signData", signData));
            nvps.add(new BasicNameValuePair("tranCode", "100001"));
            //         nvps.add(new BasicNameValuePair("callBack","http://localhost:801/callback/ghtBindCard.do"));
            //          byte[] retBytes = httpClient4Util.doPost("http://localhost:8080/quickInter/channel/commonSyncInter.do", null, nvps, null);
            byte[] retBytes = httpClient4Util.doPost(url, null, nvps, null);
            //         byte[] retBytes =httpClient4Util.doPost("http://epay.gaohuitong.com:8082/quickInter/channel/commonSyncInter.do", null, nvps, null);
            //           byte[] retBytes = httpClient4Util.doPost("http://192.168.80.113:8080/quickInter/channel/commonSyncInter.do", null, nvps, null);

            String response = new String(retBytes, "UTF-8");
            System.out.println(" ||" + new String(retBytes, "UTF-8") + "||");
            TestEncype t = new TestEncype();
            System.out.println(": ||" + t.respDecryption(response) + "||");
            System.out.println("i" + i);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.dc.gameserver.extComponents.Kit.time.DateFormatUtil.java

/**
 * formate time yyyy-MM-dd HH:mm:ss/*from   w  w  w . j  a v  a 2s.com*/
 * @return
 */
public static String getDateFormatA() {
    long nowTime = System.currentTimeMillis();
    Timestamp timestamp = new Timestamp(nowTime);
    return DateFormatUtils.format(timestamp, "yyyy-MM-dd HH:mm:ss");
}

From source file:com.dc.gameserver.extComponents.Kit.time.DateFormatUtil.java

/**
 * formate time HH:mm:ss//from  w  w  w  .  j a  v  a2 s. c  o m
 * @return
 */
public static String getDateFormatB() {
    long nowTime = System.currentTimeMillis();
    Timestamp timestamp = new Timestamp(nowTime);
    return DateFormatUtils.format(timestamp, "HH:mm:ss");
}

From source file:apm.common.utils.DateUtils.java

/**
 * ? ?yyyy-MM-dd pattern?"yyyy-MM-dd" "HH:mm:ss" "E"
 *///  w  w w  . j av a2  s  .c  o  m
public static String getDate(String pattern) {
    return DateFormatUtils.format(new Date(), pattern);
}

From source file:com.khs.report.Data.java

public static Data convertToData(String id, Date d, String format) {
    String effDate = d != null ? DateFormatUtils.format(d, format) : " ";
    return new Data(id, effDate);
}

From source file:com.alibaba.ims.platform.util.DateUtil.java

/**
 * ?/* w  w  w .  j  av  a 2  s.c o  m*/
 *
 * @param date
 * @return
 */
public static String format(Date date) {
    if (date == null) {
        return "";
    }
    return DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss");
}

From source file:apm.common.utils.DateUtils.java

/**
 *  ?yyyy-MM-dd pattern?"yyyy-MM-dd" "HH:mm:ss" "E"
 *//*from   w  w  w . j  ava  2 s .com*/
public static String formatDate(Date date, Object... pattern) {
    String formatDate = null;
    if (pattern != null && pattern.length > 0) {
        formatDate = DateFormatUtils.format(date, pattern[0].toString());
    } else {
        formatDate = DateFormatUtils.format(date, "yyyy-MM-dd");
    }
    return formatDate;
}