Gregorian class GregorianCalendar

Source: Internet
Author: User

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} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.