hxb
2022-11-24 535d69817e83737f3da6250fc6fb70da25fc1a4c
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
package com.lechange.demo.tools;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
 
public class DateHelper {
    public static Date string2Date(String time) {
        try {
            String str = time;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = (Date) sdf.parse(str);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
 
    public static String dateFormat(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(date);
        return dateString;
    }
 
    public static String dateFormatTiming(long date) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        formatter.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
        String dateString = formatter.format(date);
        return dateString;
    }
 
    public static String getTimeHMS(long time) {
        SimpleDateFormat format1 = new SimpleDateFormat("HH:mm:ss");
        Date date = new Date(time);
        String date1 = format1.format(date);
        return date1;
    }
 
    public static long parseMills(String dateTime) {
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateTime));
            return calendar.getTimeInMillis();
        } catch (ParseException e) {
            return 0;
        }
    }
}