//获取时间戳
private static String getTime()
{
Long timeStamp = System.currentTimeMillis();
String time = timeStamp.toString();
return time;
}
//将时间转换为时间戳
public static String dateToStamp(String s)
{
String res;
//设置时间模版
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
Date date = null;
try
{
date = simpleDateFormat.parse(s);
}
catch (ParseException e)
{
e.printStackTrace();
}
long ts = date.getTime();
res = String.valueOf(ts);
return res;
}
//将时间戳转换为时间
public static String stampToDate(String s)
{
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
long lt = new Long(s);
Date date = new Date(lt);
res = simpleDateFormat.format(date);
return res;
}
Java 对时间,时间戳,日期的一些操作
最新推荐文章于 2024-07-10 21:37:49 发布