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)