把util包中的代码做了一下注释,分享一下

DateUtil 类

 1 package com.java1234.util;
 2 
 3 import java.text.SimpleDateFormat;
 4 import java.util.Date;
 5 
 6 public class DateUtil {
 7     //日期的类型转换,转化为String类型输入
 8     public static String formatate(Date date,String format){
 9         String result="";
10         SimpleDateFormat sdf=new SimpleDateFormat(format);
11         if(date!=null){
12             result=sdf.format(date);//转为为string类型输出
13         }
14         return result;
15 
16     }
17     //日期的类型转换,转换为Date类型输入
18     public static Date formatString(String str,String format) throws Exception{
19         if(StringUtil.isEmpty(str)){
20             return null;
21         }
22         SimpelDateFormat sdf=new SimpelDateFormat(format);
23         return sdf.parse(str);//转化为Date类型输出
24     }
25     public static String getCurrentDateStr() throws Exception{
26         Date date=new Date();
27         SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddhhmmss");
28         return sdf.format(date);
29     }    
30 }
View Code

相关文章:

  • 2021-07-11
  • 2021-12-08
  • 2022-01-02
猜你喜欢
  • 2021-08-01
  • 2021-07-09
  • 2021-06-12
  • 2021-05-11
  • 2022-01-16
相关资源
相似解决方案