The Calandar date processing class of Java common class library

Source: Internet
Author: User

http://www.verejava.com/?id=16993050424091

/** Knowledge Points: Calandar Date processing class */import Java.util.calendar;import Java.util.gregoriancalendar;public class TestCalendar{Publ        IC static void Main (string[] args) {//Instantiate Calandar object Calendar c=new GregorianCalendar ();        Output year, month, day, time, minute, second System.out.println (C.get (calendar.year));        Note: Gregorian calendar January starts from 0 so add 1 System.out.println (C.get (calendar.month) +1);        System.out.println (C.get (calendar.date));        System.out.println (C.get (Calendar.hour));        System.out.println (C.get (Calendar.minute));        System.out.println (C.get (Calendar.second));        System.out.println (C.get (Calendar.millisecond));        Get the current date System.out.println (Datetime.getdate ());        Get current DateTime System.out.println (Datetime.getdatetime ());    Get the current date timestamp System.out.println (Datetime.gettimestamp ()); }}/** encapsulation of the date Class 1. Gets the current date 2. Gets the current date time 3. Get current timestamp */class datetime{/** get Current date */public static String GetDate ()    {Calendar c=new GregorianCalendar ();        StringBuffer buffer=new StringBuffer ();        Buffer.append (C.get (Calendar.year)). Append ("-");        Buffer.append (Addzero (C.get (calendar.month) +1)). Append ("-");        Buffer.append (Addzero (C.get (calendar.date)));    return buffer.tostring ();        }/** Gets the current date time */public static String GetDateTime () {Calendar c=new GregorianCalendar ();            StringBuffer buffer=new StringBuffer ();        Buffer.append (C.get (Calendar.year)). Append ("-");        Buffer.append (Addzero (C.get (calendar.month) +1)). Append ("-");        Buffer.append (Addzero (C.get (calendar.date))). Append ("");        Buffer.append (Addzero (C.get (Calendar.hour))). Append (":");        Buffer.append (Addzero (C.get (Calendar.minute))). Append (":");        Buffer.append (Addzero (C.get (Calendar.second)));    return buffer.tostring (); /** gets the current timestamp */public static long Gettimestamp () {Calendar c=new GregorianCalendar();    Return C.gettime (). GetTime (); }/** If month, day, time, minute, second less than 10 add 0 */public static string Addzero (int value) {string str=integer.to        String (value);        if (Str.length () <2) return 0+str;    return str; }}

http://www.verejava.com/?id=16993050424091

The Calandar date processing class of Java common class library

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.