java字符串类型和时间类型的转换

 
 
类型转换
 
  
 
 1 //Date类型转换成String类型
 2  public static String toJson(Object obj){
 3        String reuqest=null;
 4         //对象映射
 5          ObjectMapper mapper=new ObjectMapper();
 6           //设置时间格式
 7          SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy年MM月dd日");
 8           mapper.setDateFormat(dateFormat);
 9              try {
10                  reuqest=mapper.writeValueAsString(obj);
11              } catch (JsonProcessingException e) {
12                  // TODO Auto-generated catch block
13                 e.printStackTrace();
14             }
15         return reuqest;
16      }
 1 //Date类型转换成String类型
 2  public static String toJson(Object obj){
 3   String reuqest=null;
 4     //对象映射
 5        ObjectMapper mapper=new ObjectMapper();
 6        //设置时间格式
 7        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy年MM月dd日");
 8         mapper.setDateFormat(dateFormat);
 9             try {
10                reuqest=mapper.writeValueAsString(obj);
11              } catch (JsonProcessingException e) {
12                // TODO Auto-generated catch block
13               e.printStackTrace();
14            }
15         return reuqest;
16      }


猜你喜欢

转载自www.cnblogs.com/weibanggang/p/9173245.html