FTPC时间对象Time 转 java 时间对象Date 工具类
package com.rockwell.webapp.uitls;
import com.datasweep.compatibility.ui.Time;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* 转换Time和Data工具类,相关日期格式化
*
* @author xuweijun
* @date 2022/6/25
*/
public class DateTimeUtils {
public static final String DEFAULT_PATTERN1 = "yyyy-MM-dd HH:mm:ss";
public static final String DEFAULT_PATTERN2 = "yyyyMMddHHmmss";
public static final String DEFAULT_PATTERN3 = "yyyy/MM/dd HH:mm:ss";
private DateTimeUtils(){}
/**
* Date转Time
* @author xuweijun
* @date 2022/6/25 15:24
* @param date
* @return com.datasweep.compatibility.ui.Time
*/
public static Time convert2Time(Date date){
if(null == date) return null;
Calendar instance = Calendar.getInstance();
instance.setTime(date);
return new Time(instance);
}
/**
* Time转Date
* @author xuweijun
* @date 2022/6/25 15:26
* @param time
* @return java.util.Date
*/
public static Date convert2Date(Time time){
if(null == time) return null;
Calendar calendar = time.getCalendar();
return calendar.getTime();
}
/**
* 格式化
* @author xuweijun
* @date 2022/6/25 15:35
* @param date 时间
* @param pattern 格式
* @return java.lang.String
*/
public static String formatDate(Date date,String pattern){
if(null == date) return null;
if(null==pattern||"".equals(pattern.trim()))
{
pattern = DEFAULT_PATTERN1;
}
return new SimpleDateFormat(pattern).format(date);
}
/**
* 格式化
* @author xuweijun
* @date 2022/6/25 15:37
* @param time 时间
* @param pattern 格式
* @return java.lang.String
*/
public static String formatTime(Time time,String pattern){
if(null == time) return null;
if(null==pattern||"".equals(pattern.trim()))
{
pattern = DEFAULT_PATTERN1;
}
Date date = convert2Date(time);
return new SimpleDateFormat(pattern).format(date);
}
}