前言
时间类在项目中用的比较多,处理起来也比较麻烦,今天和大家分享我在项目中处理时间类的工具,主要是日期格式化成日期、日期格式化成字符串、字符串格式化成日期等方法。
工具类
package com.example.student.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @Date 2019/8/2 10:46
* @Desc 时间工具类
*/
public class DateUtil {
public static final String YEAR = "yyyy-MM-dd";
public static final long ONE_DAY = 24 * 60 * 60 * 1000L;
public static final long MINUTE_TIME = 60000L;//1分钟
public static final long HOUR_TIME = 60 * MINUTE_TIME;
public static final String FULL_NO_SECOND = "yyyy-MM-dd HH:mm";
/**
* 时间格式转化成字符串
*
* @param date 时间
* @param format 格式
* @return 字符串
*/
public static String dateToString(Date date, String format) {
String strDate = null;
if (date != null && format != null && !"".equals(format