The usage of time and date

本文介绍了几种使用Java进行时间处理的方法,包括如何通过getTime获取唯一值、日期与字符串之间的转换以及计算程序运行时间。

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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值