“00:03:25”这样的一个字符串如何转化成一个整形毫秒时间?
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
String str= "00:03:25";
Date date = sdf.parse(str);
System.out.println(date);
}
Thu Jan 01 00:03:25 CST 1970
正常时间转为毫秒是需要有年月日的,如果没有会默认1970年7月1日 时分秒,所以你问的问题大可以通过截取字符串,((3*60)+25)*1000来计算有多少毫秒.
0~9之间char和int之间的转换:
char -> int : char - '0'
int -> char : int + ‘0’
String str ="00:03:25"
int time=Integer.parseInt(str.splite(:)[0])*60*60*1000+
Integer.parseInt(str.splite(:)[1])*60*1000+
Integer.parseInt(str.splite(:)[2])*1000;
完了
String str ="00:03:25"
int time=Integer.parseInt(str.splite(:)[0])*60*60*1000+
Integer.parseInt(str.splite(:)[1])*60*1000+
Integer.parseInt(str.splite(:)[2])*1000;
当遇到字符串为“00”转为整形的时候不会报错吗?