java 字符串时间和毫秒数互转
package org.cric.e;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class TimeDateText {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
/**
* 将字符串数据转化为毫秒数
*/
String dateTime="20121025112950";
Calendar c = Calendar.getInstance();
c.setTime(new SimpleDateFormat("yyyyMMddHHmmss").parse(dateTime));
System.out.println("时间转化后的毫秒数为:"+c.getTimeInMillis());
/**
* 将毫秒数转化为时间
*/
String sstime="1339033320000";
Date date = new Date(sstime);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("毫秒数转化后的时间为:"+ sdf.format(date));
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}