Easy-to-use classes in Java

Source: Internet
Author: User

Dates are frequently used in projects, including the formatting of dates. Here are a few of the more commonly used tool classes.

ImportJava.text.SimpleDateFormat;Importjava.util.Date;Importorg.apache.commons.lang.time.DateFormatUtils;ImportOrg.apache.commons.lang.time.FastDateFormat; Public classTestController { Public Static voidmain (String [] args) {SimpleDateFormat SDF=NewSimpleDateFormat ("Yyyymmddhhmmsssss"); String ff1= Sdf.format (NewDate ());        System.out.println (FF1); Dateformatutils DF=Newdateformatutils (); Fastdateformat FF2= Fastdateformat.getinstance ("Yyyymmddhhmmsssss"); String format= Ff2.format (NewDate ());        SYSTEM.OUT.PRINTLN (format); String FF3= Dateformatutils.format (NewDate (), "Yyyymmddhhmmsssss");    System.out.println (FF3); }}

Among them, SimpleDateFormat is more commonly used, this is provided by the JDK, but this class is not thread-safe, The more thread-safe use is the Dateformatutils and Fastdateformat two tool classes provided in Apache's common package.

The operating result is:

20150901161033217
20150901161033273
20150901161033275

YYYY year

MM Month

DD Day

HH24 Hour System

MM points

SS sec

SSS milliseconds 3 bit, not enough to be padded 0

Easy-to-use classes in Java

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.