獲取時間的毫秒數
阿新 • • 發佈:2018-12-28
public static void main(String[] args) throws Exception {
String str1 = "2017-11-29 12:31";
long millionSeconds1 = sdf.parse(str1).getTime();//毫秒
System.out.println(millionSeconds1);
String str2= "2017-11-29 07:20";
long millionSeconds2 = sdf.parse(str2).getTime();//毫秒
System.out.println(millionSeconds2);
String str3 = "2017-11-29 13:00";
long millionSeconds3 = sdf.parse(str3).getTime();//毫秒
System.out.println(millionSeconds3);
if(millionSeconds1<=millionSeconds2 && millionSeconds2<millionSeconds3){
System.out.println("----------");
}
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");//24小時制
//yyyy-MM-dd hh:mm 12小時制,獲取的毫秒數會有問題,小錯誤
String str1 = "2017-11-29 12:31";
long millionSeconds1 = sdf.parse(str1).getTime();//毫秒
System.out.println(millionSeconds1);
String str2= "2017-11-29 07:20";
System.out.println(millionSeconds2);
String str3 = "2017-11-29 13:00";
long millionSeconds3 = sdf.parse(str3).getTime();//毫秒
System.out.println(millionSeconds3);
if(millionSeconds1<=millionSeconds2 && millionSeconds2<millionSeconds3){
}
}