fei.wang
2025-04-18 8c63366bfaa0b5f6e0db00abbabe0e770fc0d8dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.hxzkmonitor.util;
 
import com.github.pagehelper.util.StringUtil;
 
import java.text.SimpleDateFormat;
import java.util.Date;
 
/**
 * 日期工具类
 * @author Administrator
 *
 */
public class DateUtil {
 
    /**
     * 日期对象转字符串
     * @param date
     * @return
     */
    public static String formatDate(Date date){
        String result="";
        String format="yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sdf=new SimpleDateFormat(format);
        if(date!=null){
            result=sdf.format(date);
        }
        return result;
    }
 
    /**
     * 日期对象转字符串
     * @param date
     * @return
     */
    public static String formatDate2(Date date){
        String result="";
        String format="yyyyMMddHH";
        SimpleDateFormat sdf=new SimpleDateFormat(format);
        if(date!=null){
            result=sdf.format(date);
        }
        return result;
    }
 
    /**
     * 日期对象转字符串
     * @param date
     * @return
     */
    public static String formatDate3(Date date){
        String result="";
        String format="yyyyMMdd";
        SimpleDateFormat sdf=new SimpleDateFormat(format);
        if(date!=null){
            result=sdf.format(date);
        }
        return result;
    }
 
    /**
     * 日期对象转字符串
     * @param date
     * @return
     */
    public static String formatDate4(Date date,String format){
        String result="";
        SimpleDateFormat sdf=new SimpleDateFormat(format);
        if(date!=null){
            result=sdf.format(date);
        }
        return result;
    }
    
    /**
     * 字符串转日期对象
     * @param str
     * @param format
     * @return
     * @throws Exception
     */
    public static Date formatString(String str,String format) throws Exception{
        if(StringUtil.isEmpty(str)){
            return null;
        }
        SimpleDateFormat sdf=new SimpleDateFormat(format);
        return sdf.parse(str);
    }
    
    public static String getCurrentDateStr(){
        Date date=new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddhhmmssSSSSSSSSS");
        return sdf.format(date);
    }
    
    public static String getCurrentDatePath()throws Exception{
        Date date=new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd/");
        return sdf.format(date);
    }
    
    public static void main(String[] args) {
        try {
            System.out.println(getCurrentDateStr());
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}