A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Write a program to print current Date and Birthday

import java.util.*;
import java.text.*;

public class ProgrammingShift {

  
    public static void main(String[] args) {
        //Get current date time
        Date currentDate = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        System.out.println("Current Date: "+sdf.format(currentDate));
       
        //Convert String to Date
        try{
            String strDate = "10/20/1980";
            SimpleDateFormat sdfBirthday = new SimpleDateFormat("MM/dd/yyyy");
            Date birthday = sdfBirthday.parse(strDate);
           
            SimpleDateFormat sdfBirthday1 = new SimpleDateFormat("yyyy/MM/dd");
            System.out.println("Birthday: "+sdfBirthday1.format(birthday));
        }
        catch(Exception e)
        {
            System.out.println("e.getMessage()");
        }
  
    }
   

}

LEARN TUTORIALS

.

.