Answers for "assign date in java"

0

assign date in java

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
public class Date {
   public static void main(String[] args){
            
    String calendar[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", 
         "Oct", "Nov", "Dec"};
   
    GregorianCalendar gCalendar = new GregorianCalendar();
   
        int date = gCalendar.get(Calendar.DATE);
        int year = gCalendar.get(Calendar.YEAR);

            DateFormat dateFormat2 = new SimpleDateFormat("aa");
            String dateString2 = dateFormat2.format(Calendar.AM_PM);
            
            System.out.print("Date: ");
            System.out.print(calendar[gCalendar.get(Calendar.MONTH)]);
            System.out.print(" " + date);
            System.out.println(", " + year);
            System.out.print("Time: ");
            System.out.print(gCalendar.get(Calendar.HOUR) + ":");
            System.out.print(gCalendar.get(Calendar.MINUTE) + ":");
            System.out.println(gCalendar.get(Calendar.SECOND) + " " + dateString2);

   } 
}
Posted by: Guest on October-22-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language