有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将长度为24的字符串转换为长度为4字节的字节数组

  public static void main(String[] args){
     Date localRecvTime = new Date();           
     DateFormat converter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
     converter.setTimeZone(TimeZone.getTimeZone("GMT"));           
     String ConvertedDate =converter.format(localRecvTime);
     System.out.println(ConvertedDate.length());
     //above statement will print 24

     byte[] dateInBytes=ConvertedDate.getBytes();
     System.out.println(dateInBytes.length);
     //above statement will also print 24       

    }

上面的代码运行良好。 但是我想根据我的要求将字节array(ie. byte[] dateInBytes)的大小限制为4个字节。 有可能吗


共 (0) 个答案