The usage of time and date

阅读更多

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,SQL)