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()); 


Posted in Date   
Sign Up/ Sign In
Ask a Question

Copyright © 2018 CodesJava Protection Status SiteMap Reference: Java Wiki