import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestDate {
/**
* 时间戳转换时间
*/
public String stampToDate(String s){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Long lt = new Long(s);
Date date = new Date(lt);
String str = simpleDateFormat.format(lt);
return str;
}
/**
* 时间转换为时间戳
*/
public String dateToStamp(String s) throws ParseException {
DateFormat DateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = DateFormat.parse(s);
long lt = date.getTime();
String v = String.valueOf(lt);
return v;
}
/*public Long dateToStamp2(Long s) throws Exception {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(s);
long lt = date.getTime();
return lt;
}*/
public static void main(String[] args) throws ParseException {
/**
* 时间戳转换时间
*/
TestDate day = new TestDate();
String v = day.stampToDate("1598328000000");
System.out.println(v);
/**
* 时间转换时间戳
*/
/*Long date = new Date().getTime();
String s = String.valueOf(date);
System.out.println(s);
TestDate td = new TestDate();
String s1 = td.dateToStamp(s);
System.out.println(s1);*/
}
}