CodesJava

Easy learning with example program codes

Java get current date time


Steps to get current date time in java

  1. Creating the SimpleDateFormat object with the desire pattern.
  2. Create an object of Date class.
  3. Call the format() method of DateFormat class and pass the date object as an argument to the method.

Java get current date time example

package com.codesjava;
 
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class GetDateTime {
	public static void main(String args[]){
		SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
		String date = sdf.format(new Date()); 
		System.out.println(date);
	}
}

Output:

09-04-2018
Posted in Date   


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki