Java Learning Day 13th (Java gets the current time, operations on big data and exact numeric operations, date Class)

Source: Internet
Author: User
Tags time in milliseconds

One Java gets the current time

Learn a function to get the exact value of the current time System.currecttimemillis (). You can get the current time in milliseconds. It is mainly used to calculate the program run time, Long Start=system.currecttimemillis (), Long Stop=system.currecttimemillis (), Stop-start;

Two operations on big data and precise numerical operations.

The integer does not apply at this time.    We use BigInteger, such as: BigInteger b= new BigInteger ("12364812255474"); In Java If you execute System.out println (0.09+0.01), it results in 0.09999999, which is caused by the difference in floating point number storage with integers, we use bigdecimal, which is very necessary in finance. Construction method BigDecimal (String s), subtraction can go to see the API documentation, for example BigDecimal a=new BigDecimal ("0.01")

BigDecimal b=new BigDecimal ("0.09"), System.out println (A.add (b));

Three date classes

Date is a class of dates that can be accurate to milliseconds.

A: Construction method
Date ()
Date (long time)
B: Member Method
GetTime ()
SetTime (long time)

Our main use is not to get time but date and string conversion, the main use of the class is SimpleDateFormat, it can parse the date, can also format the date, for example.

Date-----String

Date D=new date ();

SimpleDateFormat s=new SimpleDateFormat ()//Note what we want if it is a clearer string, you need string str=s.fo Rmat (s)// SimpleDateFormat in the format of the provisions.             For example sysytem.out.println (str); SimpleDateFormats=new simpledateformat ("YYYY:MM:dd:HH:mm:ss")

String-----Date

Date Dd=new date ();

String str= "November 20, 2016 0:43 55 sec"

SimpleDateFormat s=new SimpleDateFormat ("yyyy year mm month hh point mm min ss sec")

Dd=s.parse (str)//note here to throw an exception, regardless of the direct throw exection.                                        

SYSYTEM.OUT.PRINTLN (DD);

Java Learning Day 13th (Java gets the current time, operations on big data and exact numeric operations, date Class)

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.