【JavaSE】 4. 常用 API (二) Math 、 Object 、 Date 、 Calendar



title: JavaSE_4.常用API(二)Math、Object、Date、Calendar
date: 2020-11-01 20:01:08
tags: JavaSE

Math class

Class variable

  • public static final double
Math.E  =  2.718
Math.PI =  3.1416

Class method:

  • Base class overload
Math.abs()
Math.min()
Math.max()
  • double
Math.pow
Math.sqrt()
Math.random()    //\[0.0,1.0)随机数

Object ancestor class

Date date and time class

We can see various date and data format conversion classes in the Java.util package.

Date class

The SimpleDateFormat class is a concrete class used to format and parse dates (under the Java.text package)

SimpleDateFormat sdf = new SimpleDateFormat("想要的格式,yyMMdd子类的东西")


parse(String  str)
format(Date date)
  • You only need to know that yyyy, dd, hh, mm, and ss are the year, month, and day. Because the sub occupies the lowercase m, the month is special and should be written in uppercase M. a means morning or afternoon
  • Parse re-converts str into a date type object, where str must match the format of the corresponding object. (The format is the same as the one written by yourself)
  • Format is something that turns a date object into a string, making a thing more personalized. Let's call him a personalized date format, but this must also create a date format object.
  • So we know that the object we created is a date format object , and we use this object to personalize date objects. (It turns into a string, and turns a string of personalized strings into a date object)

Calendar class

Guess you like

Origin blog.csdn.net/weixin_43801418/article/details/110728613