首页>代码>Spring Hibernate Spring Data MongoDB Akka Titles Bootstrap JQuery Maven 大全>/ykameshrao-spring-hibernate-springdata-springmvc-maven-project-framework-6ed60ce/commons/src/main/java/com/yourpackagename/commons/util/CommonUtils.java
/**
 * @filename CommonUtils.java
 * @author Y.Kamesh Rao
 */
package com.yourpackagename.commons.util;

import java.util.Calendar;

/**
 * Class that consists of the commonly used small utilities
 *
 * @author Y.Kamesh Rao
 */
public class CommonUtils {
    /**
     * Returns the current timestamp in timezone independent way
     *
     *
     * @return String form timestamp
     */
    public static String getTimestamp() {
        String created;
        Calendar cal = Calendar.getInstance();

        int year = cal.get(Calendar.YEAR);

        String month = (cal.get(Calendar.MONTH) + 1) + "";
        if (month.length() != 2) {
            month = "0" + month;
        }

        String day = cal.get(Calendar.DAY_OF_MONTH) + "";
        if (day.length() != 2) {
            day = "0" + day;
        }

        String hour = cal.get(Calendar.HOUR_OF_DAY) + "";
        if (hour.length() != 2) {
            hour = "0" + hour;
        }

        String minute = cal.get(Calendar.MINUTE) + "";
        if (minute.length() != 2) {
            minute = "0" + minute;
        }

        String second = cal.get(Calendar.SECOND) + "";
        if (second.length() != 2) {
            second = "0" + second;
        }

        created = year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":" + second + "Z";

        return created;
    }


    /**
     * Converts the data to hex representation.
     *
     * @param data The data to be converted
     * @return
     */
    public static String toHex(final byte[] data) {
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < data.length; i++) {
            int intData = (int) data[i] & 0xFF;
            if (intData < 0x10)
                buf.append("0");
            // Display 2 digits per byte i.e. 09
            buf.append(Integer.toHexString(intData));
        }
        return (buf.toString());
    }
}
最近下载更多
13043860zj  LV16 2020年9月3日
码码码  LV5 2019年4月22日
50636315  LV2 2017年9月30日
ykcro123  LV11 2017年3月2日
刻下来的幸福  LV2 2017年2月5日
zhoushi18  LV7 2016年7月18日
chenda  LV4 2016年6月22日
zang1314  LV2 2016年6月21日
lcjz99  LV11 2016年4月14日
abingagl  LV8 2016年1月24日
最近浏览更多
Dominick  LV14 2023年6月19日
irivn007  LV15 2022年12月24日
Add_Wa  LV1 2022年11月18日
Super强  LV13 2022年10月21日
291373020  LV7 2022年5月31日
fengshengtian  LV8 2022年2月26日
lingtiejing  LV15 2022年2月23日
1615651451  LV2 2021年12月7日
weixiao  LV6 2021年11月8日
1872615558  LV13 2021年11月2日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友