java中怎样把毫秒转成时间类型?
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Cat {
public static void main(String[] args) throws ParseException {
String str = "201104141302";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmm");
long millionSeconds = sdf.parse(str).getTime();//毫秒
System.out.println(millionSeconds);
}
}
具体操作方式:
键入语句
public static void main(String[] args) {
Date date = new Date();
Long time = date.getTime();
System.out.println(time);
Date d = new Date(time);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(sdf.format(d));
}
用SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
调用dateFormat.format(time);
广告 您可能关注的内容 |