Sunday, December 19, 2010

Getting current Date and Time in Java

This example is for Java beginners to learn use of Java Date Format

import java.util.Date;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

public class Main {

    public Main() {

    }

    public static void main(String[] args) {       

         Date today = new Date();

         DateFormat df=new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");

         java.sql.Date date=new java.sql.Date(today.getTime());       

         System.out.println(df.format(date));     

    }   

}

No comments:

Post a Comment