20201225-禹娜
String中的储存情况
private final byte[] value; 储存了字节数组
private final byte coder;
1.如果字符串仅包含了ISO-8859-1字符集中的字符,这个字符集就按照ISO-8859-1字符集编码(出现在键盘上的)。此时String实例中的 coder 取值为 0.
2.如果字符中包含了除了ISO-8859-1字符集之外的字符(除了键盘上以为外的),那么这些字符集就按照UTF-16LE字符集编码。此时String实例中的coder取值为1.
private int hash;
hash的默认值为0,一旦赋值后,hash的值就不可以改变了。
Date类
Date在java.util包中。
了解什么是历元?格林威治的标准时间 1970年1月1日的00:00:00:000
在java语言中传统的表示时间的方法是参照 历元 来获取偏移量
例
long millis=System.currentTimeMillis();
System.out.println(millis )
构造方法
Date(); 表示分配对象时的时间。
Date (long millis);表示用指定的时间来构造对象
实例方法:
getTime()获得 实例 内部所保存的 毫秒值
SetTime()修改内部保存的值
before( Date when ) 若 当前Date实例表示的瞬间 早于 参数when表示的瞬间 就返回 true
after( Date when ) 若 当前Date实例表示的瞬间 晚于 参数when表示的瞬间 就返回 true
LocalDate类
LocalDate 是 Java 8 新增的 最终类( final class )
LocalDate 类 的 实例 都是 不可变对象 ( year / month / dateOfMonth )
获得当前日期:
LocalDate today=LocalDate.now();
System.out.priontln(today);
获得指定日期:
LocalDate birthday=LocalDate.of(1996, 8, 1)
System.out.println(birthday);
获得当前时间:
LocalTime today1=LocalTime.now();
System.out.println(today1);
获得指定的时间:
LocalTime birthday1=LocalTime.of(4, 34, 45);
System.out.println(birthday1);
Calendar 类
Calendar 类是一个抽象类,GregorianCalendar 类是 Calendar 非抽象的子类
Calendar 为特定瞬间与一组日历字段之间的转换提供了一些方法,并为操作日历字段提供了一些方法。
获得当前年/月/日
Calendar calendar = new GregorianCalendar();
int year=calendar.get(Calendar.YEAR);
System.out.println(year);
注意:月份是从0开始的。
根据 Calendar实例 来获得 java.util.Date 实例
1、获得 Calendar实例 (用它充当一个容器)
Calendar calendar = Calendar.getInstance() ;
// 调用 Calendar类中的 类方法来返回 Calendar实例
2、清空 Calendar实例 中 所有日历字段的值
calendar.clear();
3、根据实际需要依次设置 年、月、日、时、分、秒、毫秒 等日历字段的值
calendar.set( 2021 , 0 , 1 , 13 , 30 , 40 );
4、根据 Calendar实例 获得 Date实例
近期评论