[TOC]
date日期轉(zhuǎn)long日期
import java.util.Date;
/**
* long日期轉(zhuǎn)date
*
* @param longTime
* @return
*/
public static long dateToLongTime(Date date) {
return date.getTime();
}
long日期轉(zhuǎn)date日期
import java.text.SimpleDateFormat;
import java.util.Date;
private static final String formatStr = "yyyy-MM-dd";
/**
* date日期轉(zhuǎn)long
*
* @param date
* @return
*/
public static String longTimeToDate(long longTime) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr);
Date date = new Date(longTime);
return simpleDateFormat.format(date);
}
String日期轉(zhuǎn)long日期
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
private static final String FORMATSTR = "yyyy-MM-dd";
/**
* string日期轉(zhuǎn)long
*
* @param date
* @return
*/
public static Long dateToLongTime(String dateStr) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMATSTR);
Date date = new Date();
try {
// 注意格式需要與上面一致客冈,不然會(huì)出現(xiàn)異常
date = simpleDateFormat.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return date.getTime();
}
String日期轉(zhuǎn)date日期
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
private static final String FORMATSTR = "yyyy-MM-dd";
/**
* string日期轉(zhuǎn)long
*
* @param dateStr
* @return
*/
public static Date dateStrToDate(String dateStr) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMATSTR);
Date date = new Date();
try {
// 注意格式需要與上面一致,不然會(huì)出現(xiàn)異常
date = simpleDateFormat.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}