SYSTEM DATE AND TIME

  

let us consider we have the test cases in which we have to validate some records with date and time. so to handle this we must have to get system date and time.

         Before getting date and time we must have to know few important points

In which format you want date and time.


MM/dd/yyyy HH:mm:ss
dd/MM/yyyy HH:mm:ss
yyyy/dd/MM HH:mm:ss
yyyy/MM/dd HH:mm:ss

  1. you can chose any one format that you want
  2. You have to use simpleDateFormat class.
  3. You have to crate object of simpleDateFormat class.
  4. Get the current date and time of the  system.
  5. Format the date is required. 

package mypackage;

 

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

 

public class SystemDateAndTime {

 

public static void main(String[] args) {

DateFormat date=new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

Date systemdate=new Date();

String dateandtime=date.format(systemdate);

System.out.println(dateandtime);

}

}