2022-7-28 第七组姜珊学习笔记
Api
java的值传递
本质上Java只有值传递,所有赋值传参都是一次值的拷贝。
引用数据类拷贝的是地址,基本数据类型拷贝的是值,不会传入实例对象
API;Application programing Interface)应用程序接口
JDK提供的一些写好的类,可以直接调方法解决
我们类的方法,在宏观上都可以称为接口
时间相关api
时间:格林泥治,天文台,伦敦
时区:东八区
北京时间,+8
时间戳:1970.1.1 00:00:00.到今天具体到秒的毫秒数
1s=1000ms,1min=60s,1h=60min,1day=24h.时间戳全世界都是固定的
public class Ch03{
public static void main(String[]args){
System.out.println(System.currentTimeMillis())//获取当前时间戳
}
}
//System.currentTimeMillis()时间戳
可以通过时间戳转换成我们当前所在地的具体时间和日期
日期类Date
获取系统当前日期
Date date=new Date();
System.out,println(date);
打印输出7天以后是哪一天
public class Demo01{
Date date=new Date()//获取当前时间。
long mills=date.getTime()+1000*60*60*24*7//获取当前的毫秒数+七天的毫秒数
System.out.println(new Date(mills))//通过匿名对象打印输出
}
日历类:日期
Calender是一个抽象类。
初始化:
提供了一组对年月日时分秒星期等信息的操作函数,操作不同时区的信息
JDK1,1版本开始,在处理时间和日期时系统推荐使用Canender类
Calendar要比Date强大的多
public class Ch06{
public static void main(String[]args){
Canender canender=Canender.getInstance();
system.out.println(calender.get(Calender.YEAR))
}
}
时区:
public class Ch06{
public static void main(String[]args){
Canender canender=Canender.getInstance();
calendar.setTimeZone.getTimeZone(GMT-8))//获取时区
}
}
日期格式化
SimpleDateFormat
format:格式化Date类型,把Date类型转成String类型(要展示数据到客户端)
parse:把String类型的时间转成Date类型 (从客户端传过来的时间,一般是String类型,存入数据库。)
public class Demo01{
Date date=new Date()//获取当前时间。
system.out.println(date)
SimpleDateFormat sdf=new impleDateFormat(“yyyy年MM月DD日 HH:mm:ss.SSS”)
}
String s=sdf.format(date );//date转换为string类型
System.out.println(s)
yyyy:年
yy:年的后两位
MM:月
dd:日
HH:小时24小时制
hh:小时12小时制
mm:分
ss:秒
SSS:毫秒
JDK8的时间类
在jdk8之前,处理时间和日期,基本上用上面几个类
Date和Calender,获取到的月份都是0-11,而不是我们生活的1-12
阿里巴巴规约的明确要求:
如果是jdk8的应用可以使用Instant代替Date
LocalDateTime代替Calendar
DateTimeFormatter代替simpleDateFormat
新的实践类
Instant:时间线上的某一个瞬间
LocalDate:获取当前日期
Local Time:
LocalDateTime:
DateTimeFormatter:处理日期格式化问题
objects:
public static void main(String[] args) {
System.out.println(Objects.isNull(""));
}
}
判断是不是空
StringBuffer 和StringBuilder
可变的字符序列,和string有本质区别
public static void main(String[] args) {
stringBuffer stringBuffer=new StringBuffer('你好')
System.out.println(stringBuffer)
}
}
获取功能的方法
int length() :获取字符串长度
String concat(String str):将指定的字符串连接到该字符串的末尾
char charAt(int index):返回指定索引处的char值
int indexOf(String str):返回是指定子字符串第一次出现该字符串内的索引
String substring(int beginIndex):返回一个子字符串,从beginIndix开始一直到末尾
String substring(int beginIndex,int endIndex):返回一个子字符串,
beginIndex,~endIndex-》左闭右开
心得:
学的感觉有点乱,有点消化慢