Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Tuesday, 19 November 2013

Calculation of Execution /Elapsed Time in Java

Two Java function can be use to calculate the elapsed time or execuiton time in java.

  1. System.currentTimeMillis()
  2. System.nanoTime()

Example:

System.currentTimeMillis()

 long StartTime = System.currentTimeMillis();
 //do some tasks
 long EndTime = System.currentTimeMillis();
 long difference = EndTime - StartTime;
 
 System.out.println("Elapsed milliseconds: " + difference);

Saturday, 16 November 2013

Java Date And Calendar Examples

This tutorial shows you how to work with java.util.Date and java.util.Calendar.

1. Java Date Examples

Few examples to work with Date APIs.

Example 1.1 – Convert Date to String.

 SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy");
 String date = sdf.format(new Date());
 System.out.println(date); //15/10/2013