时间格式化问题。。。。急 20070725T160000 怎么把它转为 毫秒, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String str="20070725T160000";String[] a=str.split("T");String d=a[0];String t=a[1];FormatDate f=new FormatDate();SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");java.util.Date date1=new Date();try{ date1=df.parse(d);}catch(Exception e){ System.out.println(e);}long ms=date1.getTime()+Long.parseLong(t);搂主是这个意思吗?是的话,记得给分呀 如果 T 后面是时分秒的话,可以把 T 去掉,再进行解析:String str="20070725T160000";str = str.replace("T", "");SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");Date date = df.parse(str);System.out.println(date.getTime()); bao110908(长牙了,好痛) ( ) 信誉:100 正解 String str="20070725T160000"; //分析你的时间格式String[] a=str.split("T"); //以“T”为分割符,分开T前和T后数据String times=a[0]+a[1]; //a[0]为T前部分,a[1]为T后部分,组合两字符串为timesCalendar cal = Calendar.getInstance();//通过Calendar类来处理时间,先初始化该类Integer nian=new Integer(times.substring(0,4));//截取字符串转换为int类型Integer yue=new Integer(times.substring(4,6));//截取字符串转换为int类型Integer ri=new Integer(times.substring(6,8));//截取字符串转换为int类型Integer shi=new Integer(times.substring(8,10));//截取字符串转换为int类型Integer fen=new Integer(times.substring(10,12));//截取字符串转换为int类型Integer miao=new Integer(times.substring(12,14));//截取字符串转换为int类型cal.set(nian.intValue(),yue.intValue(),ri.intValue(),shi.intValue(),fen.intValue(),miao.intValue());//通过设置年月日时分秒cal.getTimeInMillis();//从Calendar类中的getTimeInMillis方法获得毫秒数注意:获得是毫秒数。 上边直接通过jdk提供的Calendar类来实现,通过这个类可以实现大多数的时间转换。 long haomiaoshu=cal.getTimeInMillis();//long型的毫秒数你可以进行处理毫秒数:haomiaoshu获得秒:haomiaoshu/1000获得分:haomiaoshu/1000/60获得时:haomiaoshu/1000/60/60注释很全了,应该很容易理解了。 to: zhao0p设置月时,需要减去 1 的,因为 1 月份是“0”。 new SimpleDateFormat("yyyyMMdd'T'HHmmss").parse("20070725T160000").getTime(); ->bao110908呵呵大意了!是应该减一 如何设置线程的优先级 为什么test为空了,还能使用test.i,打印出7来? JAVA 位运算符和逻辑运算符 问个java编程思想里的例子 版面信息交互问题 请问,连续生成大量的zip文件,比如几百个,有什么好一点的高性能方案吗? 访问权限问题! 大家来帮忙解一道题吧! 关于String 的困惑,高手帮帮忙 [ 求助 ] 两个小问题,请大虾指教~ Button添加事件监听器问题 java多线程,运行后机子越来越慢,如何解决
String[] a=str.split("T");
String d=a[0];
String t=a[1];
FormatDate f=new FormatDate();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
java.util.Date date1=new Date();
try{
date1=df.parse(d);
}catch(Exception e){
System.out.println(e);
}
long ms=date1.getTime()+Long.parseLong(t);
搂主是这个意思吗?是的话,记得给分呀
str = str.replace("T", "");
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = df.parse(str);
System.out.println(date.getTime());
正解
String[] a=str.split("T"); //以“T”为分割符,分开T前和T后数据
String times=a[0]+a[1]; //a[0]为T前部分,a[1]为T后部分,组合两字符串为times
Calendar cal = Calendar.getInstance();//通过Calendar类来处理时间,先初始化该类
Integer nian=new Integer(times.substring(0,4));//截取字符串转换为int类型
Integer yue=new Integer(times.substring(4,6));//截取字符串转换为int类型
Integer ri=new Integer(times.substring(6,8));//截取字符串转换为int类型
Integer shi=new Integer(times.substring(8,10));//截取字符串转换为int类型
Integer fen=new Integer(times.substring(10,12));//截取字符串转换为int类型
Integer miao=new Integer(times.substring(12,14));//截取字符串转换为int类型
cal.set(nian.intValue(),yue.intValue(),ri.intValue(),shi.intValue(),fen.intValue(),miao.intValue());//通过设置年月日时分秒
cal.getTimeInMillis();//从Calendar类中的getTimeInMillis方法获得毫秒数
注意:获得是毫秒数。
毫秒数:haomiaoshu
获得秒:haomiaoshu/1000
获得分:haomiaoshu/1000/60
获得时:haomiaoshu/1000/60/60注释很全了,应该很容易理解了。