各种字符串转换方法

//毫秒值转换为日期
public static String  millToDate(long millisecond){
    Date d = new Date(millisecond);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
    return sdf.format(d);
}
//日期转换为毫秒值
 public static long dateToMilles(String date){
     long time = 0;
     SimpleDateFormat dateformat = new SimpleDateFormat("yyyyMMdd"); //时间格式
     try {
       time = dateformat.parse(date).getTime();//格式转换

     } catch (java.text.ParseException e) {
         e.printStackTrace();
     }
     return time;

 }
 //16进制转换为10进制
  public static int  hexToint(String hex_num){
   int dec_num = Integer.parseInt(hex_num, 16);

    return  dec_num;
}
/**
 * 16进制转2进制字符串
 *
 * @param hexString
 * @return
 */
 public static String hexString2binaryString(String hexString) {
            if (hexString == null || hexString.length() % 2 != 0)
                return null;
            String bString = "", tmp;
            for (int i = 0; i < hexString.length(); i++) {
                tmp = "0000"
                        + Integer.toBinaryString(Integer.parseInt(hexString
                        .substring(i, i + 1), 16));
                bString += tmp.substring(tmp.length() - 4);
            }
            return bString;
        }
/**
 * bytes转换成十六进制字符串
 */
public static String byte2HexStr(byte[] a) {

    String hs = "";
    String stmp;
    for (int n = 0; n < a.length; n++) {
        stmp = (Integer.toHexString(a[n] & 0XFF));
        if (stmp.length() == 1)
            hs = hs + "0" + stmp;
        else
            hs = hs + stmp;
    }
    return hs.toUpperCase();
}


    //16进制字符串转换为指定长度的字符串,不足补0
    
    public static String hexLength(String hex,int length){

         int l = hex.length();
         if(l<length){
             int s = length -l;
             for(int i=0;i<s;i++){
                 hex ="0"+hex;
             }
         }
        
         return hex;
    }

给定一个日期转换为指定日期的字符串格式

    public static String dateFormate1(String date ,String OriginalDf ,String destDf) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(OriginalDf);
            Date d = sdf.parse(date);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(de

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值