package test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test1 {
public static void main(String[] args) throws Exception{
try {
String date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
long time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date).getTime();
int time1=(int)(time/1000);
System.out.println(time);
System.out.println(time1);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这里需要注意的是.这样的做法会把毫秒的精度损失,如果想精确到分得话,在这个基础上再除以60就OK了.希望对大家有用.