Using the Gregorian class GregorianCalendar, the Gregorian class GregorianCalendar has a method Settimeinmillis (long), which can be used to set a specific time from January 1, 1970. Please enter a long integer value from the keyboard and then output the corresponding year, month, and day. For example
Input: 1234567898765
Output: 2009-02-14
Reference Code
Method One:
Import Java.text.SimpleDateFormat;
Import java.util.Date;
Import Java.util.GregorianCalendar;
Import Java.util.Scanner;
public class gregorian{public
static void Main (string[] args) {
GregorianCalendar gc=new GregorianCalendar (); C6/>scanner in=new Scanner (system.in);
Long Millis=in.nextlong ();
Gc.settimeinmillis (Millis);
Returns a Date object representing this GregorianCalendar time value of
date Date=gc.gettime ();
Creates a SimpleDateFormat object that specifies the format of the date time
simpledateformat sdf = new SimpleDateFormat ("Yyyy-mm-dd");
Outputs System.out.println in the specified time format
(Sdf.format (date));
}
Method Two:
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import
Java.util.GregorianCalendar;
Import Java.util.Scanner; public class Gregorian {public static void main (string[] args) {GregorianCalendar gc=new GregorianCalendar ()
;
Scanner in=new Scanner (system.in);
Long Millis=in.nextlong ();
Gc.settimeinmillis (Millis);
System.out.println (Gc.get (calendar.year) + "-" + (Gc.get (calendar.month) +1) + "-" +gc.get (Calendar.day_of_month)); }//0 means January, so add a}