日期转换工具类 CommUtil.java
分类:
IT文章
•
2024-07-12 16:50:12
- package com.util;
-
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
-
- public class CommUtil {
-
-
- public static String dateToString(Date time) {
-
- SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd");
- String stringTime = formatter.format(time);
-
- return stringTime;
-
- }
-
- public static String dateTimeToString(Date time) {
-
- SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMdd");
- String stringTime = formatter.format(time);
-
- return stringTime;
-
- }
-
-
-
- public static Date dateToDate(Date time) {
-
- SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd");
- String stringTime = formatter.format(time);
- Date date = null;
- try {
- date = formatter.parse(stringTime);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return date;
-
- }
-
-
- public static String getDate(){
- Date date = new Date();
- return CommUtil.dateToString(date);
- }
- }