There are some usage of time we often used for developping,here is my submit
:
one:
Get the unique value by getTime
import java.sql.Timestamp;
import java.util.Date;
Date date=new Date();
Timestamp st=new Timestamp(date.getTime());
String uniqueStr="U";
uniqueStr=uniqueStr+st.getTime(); //the sum of microsecond from 1970
two :
The transition of Date and String()
public class StringToDate {
public static Date stringToDate(String dateString){
Date date;
try {
date = new SimpleDateFormat("yyyy-MM-dd").parse(dateString);
return date;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
Three, when we want to calculate the time of execution of our program:
long startTime = System.currentTimeMillis();
long endTime = System.currentTimeMillis();
System.out.println("The time used is "+(endTime-startTime)+" ms");
If you have some good methods of time ,pls share it!
本文介绍了几种使用Java进行时间处理的方法,包括如何通过getTime获取唯一值、日期与字符串之间的转换以及计算程序运行时间。
1949

被折叠的 条评论
为什么被折叠?



