Java SE 学习笔记(使用接触API)

1、 字符串相关的类

Ø String
Ø StringBuffer
Ø StringBuilder
 
 

 

 

 

 

 

 

 

 

 

 

2、 JDK 8之前时间日期API

Ø System
Ø Date
Ø SimpleDateFormat
Ø Calendar

3、 JDK8中新时间日期API

方法

描述

示例

now()

静态方法,根据当前时间创建对象

LocalDate localDate = LocalDate.now();

LocalTime localTime = LocalTime.now();

LocalDateTime localDateTime = LocalDateTime.now();

of()

静态方法,根据指定日期/时间创建对象

LocalDate localDate = LocalDate.of(2016, 10, 26);

LocalTime localTime = LocalTime.of(02, 22, 56);

LocalDateTime localDateTime = LocalDateTime.of(2016, 10, 26, 12, 10, 55);

plusDays, plusWeeks,

plusMonths, plusYears

向当前 LocalDate 对象添加几天、几周、几个月、几年

 

minusDays, minusWeeks,

minusMonths, minusYears

从当前 LocalDate 对象减去几天、几周、几个月、几年

 

plus, minus

添加或减少一个 Duration Period

 

withDayOfMonth,

withDayOfYear,

withMonth,

withYear

将月份天数、年份天数、月份、年份修改为指定的值并返回新的 LocalDate 对象

 

getDayOfMonth

获得月份天数(1-31)

 

getDayOfYear

获得年份天数(1-366)

 

getDayOfWeek

获得星期几(返回一个 DayOfWeek 枚举值)

 

getMonth

获得月份, 返回一个 Month 枚举值

 

getMonthValue

获得月份(1-12)

 

getYear

获得年份

 

until

获得两个日期之间的 Period 对象,或者指定 ChronoUnits 的数字

 

isBefore, isAfter

比较两个 LocalDate

 

isLeapYear

判断是否是闰年

 

To 遗留类

From 遗留类

java.time.Instant
java.util.Date

Date.from(instant)

date.toInstant()

java.time.Instant
java.sql.Timestamp

Timestamp.from(instant)

timestamp.toInstant()

java.time.ZonedDateTime
java.util.GregorianCalendar

GregorianCalendar.from(zonedDateTime)

cal.toZonedDateTime()

java.time.LocalDate
java.sql.Time

Date.valueOf(localDate)

date.toLocalDate()

java.time.LocalTime
java.sql.Time

Date.valueOf(localDate)

date.toLocalTime()

java.time.LocalDateTime
java.sql.Timestamp

Timestamp.valueOf(localDateTime)

timestamp.toLocalDateTime()

java.time.ZoneId
java.util.TimeZone

Timezone.getTimeZone(id)

timeZone.toZoneId()

java.time.format.DateTimeFormatter
java.text.DateFormat

formatter.toFormat()

4、 JDK8中的Optional

5、 Math

6、 BigInteger 类与BigDecimal

 

发布了284 篇原创文章 · 获赞 45 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/qq_31784189/article/details/104212315
今日推荐