A date date class for Java common class libraries

Source: Internet
Author: User

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

/** Knowledge Points: Date dates class */import Java.util.date;import java.text.simpledateformat;public class testdate{public static void        Main (string[] args) {//Get system Current date date=new date ();        SYSTEM.OUT.PRINTLN (date);                Obtained year System.out.println (Date.gettime ());        Get current DateTime System.out.println (Cdate.getcurrentdatetime ());    System.out.println (Cdate.stringtodate ("2000-12-12 00:00:00")); }}class cdate{/** Gets the current datetime string */public static string GetCurrentDateTime () {Date date=new D        Ate ();        The format of the date SimpleDateFormat df=new simpledateformat ("Yyyy-mm-dd HH:mm:ss");        String Datestr=df.format (date). toString ();    return datestr; }/** date is converted to a formatted string */public static string datetostring (date date) {//Date formatted simple        DateFormat df=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");        String Datestr=df.format (date). toString ();    return datestr;   }    /**     String converted to date */public static date Stringtodate (String datestring) {try{SimpleDateFormat            Df=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");        Return Df.parse (datestring);            }catch (Exception e) {e.printstacktrace ();        return null; }    }}

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

A date date class for Java common class libraries

Related Article

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.