Answers for "how to store a date in java"

22

java how to get current date

import java.time.format.DateTimeFormatter;  
import java.time.LocalDateTime;    
public class CurrentDateTimeExample1 {    
  public static void main(String[] args) {    
   DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");  
   LocalDateTime now = LocalDateTime.now();  
   System.out.println(dtf.format(now));  
  }    
}
Posted by: Guest on June-10-2020
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 "how to store a date in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language