A common method of the Dark Horse programmer--java--date Class Demo

Source: Internet
Author: User
Tags dateformat time and date



Common methods in Date demo
Import Java.text.dateformat;import Java.text.parseexception;import Java.text.simpledateformat;import Java.util.date;public class Datedemos {public static void main (string[] args) throws Exception {//Gets the system's current time millisecond value long L = S Ystem.currenttimemillis (); System.out.println (l);//1434811870917//encapsulates the current time and date as an object date d = new Date (); System.out.println (d);//sat June 22:51:10 CST 2015//encapsulates the specified milliseconds as an object date D1 = new Date (l); System.out.println (D1);//sat June 22:51:10 CST 2015/** * Millisecond Value-Date object: *.         New Date (Timemillis) by constructing a Date object; * *. You can also set it through SetTime.         Because the date object can be used to manipulate the fields (year, month, and so on). * Date Object--Millisecond value: * 1.        GetTime method.        * because it can be calculated by a specific value.       * Format Date Object: * String with Date object and date format. * The Format method in the DateFormat class is used. */system.out.println ("_________________________________________");//Gets the current time value of date D2 = new Date ();// Gets the Date object format DateFormat df = dateformat.getdateinstance (); String dat1= Df.format (D2); System.out.println (DAT1); System.out.println ("_________________________________________ ");//Gets the date of the custom format display df = new SimpleDateFormat (" Yyyy--mm--dd "); String dat2= Df.format (D2); System.out.println (DAT2);/** * Converts a date-formatted string to a Date object using the Prase method in the DateFormat class. */string str1= "June 20, 2015";D ateformat DF1 = dateformat.getdateinstance (dateformat.long);D ate Date = Df1.parse (STR1); SYSTEM.OUT.PRINTLN (date);//sat June 00:00:00 CST 2015}}

To run the program:



A common method of the Dark Horse programmer--java--date Class Demo

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.