1 package gboat2.attachment.util;
2
3
4
5 import java.text.DateFormat;
6 import java.text.ParseException;
7 import java.text.SimpleDateFormat;
8 import java.util.Date;
9
10 import org.apache.commons.lang3.StringUtils;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 public class DateUtil {
15 private static final Logger logger = LoggerFactory.getLogger(DateUtil.class);
16
17
18
19
20
21
22
23
24
25 public static Date parse(String dateStr,String format){
26 SimpleDateFormat f = new SimpleDateFormat(format);
27 Date date = null;
28 try {
29 date = f.parse(dateStr);
30 } catch (ParseException e) {
31 logger.debug(e.toString());
32 }
33 return date;
34 }
35
36
37
38
39
40
41
42 public static String format(Date date,String format){
43 SimpleDateFormat f = new SimpleDateFormat(format);
44 String valiString = "";
45 valiString = f.format(date);
46 return valiString;
47 }
48
49
50
51
52
53
54
55 public static Date parseDate(Date date,String formatStr){
56 DateFormat df = new SimpleDateFormat(formatStr);
57 Date result = null;
58 try {
59 result = df.parse(df.format(date));
60 } catch (ParseException e) {
61 logger.debug(e.toString());
62 }
63 return result;
64 }
65
66 public static String[] stripDate(Date date){
67 String dateStr = format(date,"yyyy-MM-dd");
68 return StringUtils.split(dateStr,"-",0);
69 }
70 }