日期类

日期类

java.util.Date:表示日期和时间的类

毫秒:1000毫秒=1秒
时间原点:格林威治时间 1970年1月1日 00:00:00	1970年1月1日 08:00:00

构造方法:
new Date():空参构造返回时间原点到当前时间
new Date(long time):根据构造方法中的参数返回时间

成员方法:
long getTime():返回毫秒数,相当于		   System.currentTimeMillis():返回当前毫秒

SimpleDateFormat

java.lang.Object
java.text.Format
java.text.DateFormat :日期时间格式化抽象类
子类SimpleDateFormat继承DateFormat

构造方法:

格式化:日期->文本	文本->日期
		y年 M月 d日 H时 m分 s秒
SimpleDateFormat() 
SimpleDateFormat(String pattern) 
--SimpleDateFormat(String pattern, DateFormatSymbols formatSymbols) 
--SimpleDateFormat(String pattern, Locale locale) 

成员方法:

Date parse(source) :文本字符串转为Date日期
	**:字符串格式不匹配,ParseException异常
String format(Date date):Date日期转为文本字符串
--StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition pos) 

文本->日期

创建SimpleDateFormat对象,在构造方法中传入指定的格式
调用SimpleDateFormat对象,对象方法parse(),将符合构造方法中格式的字符串解析为Date对象
注意:parse()会抛出ParseException异常

日期->文本

创建SimpleDateFormat对象,在构造方法中传入指定的格式
调用SimpleDateFormat对象中的方法format(),按照构造方法中指定的格式,将Date对象格式化为字符串

System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)将指定源数组中的数组从指定位置复制到目标数组的指定位置。

Calendar

java.util.Calendar日历类抽象类

可以通过static Calendar getInstance()来获取Calendar类的对象

方法

int get(int i):返回给定日历字段的值
void set(int i,int value):给 日历字段设定值
void add(int i,int j):根据日历规则,给指定的日历字段添加或者减去时间量,整数为+,负数为-
Date getTime();
posted @ 2023-05-01 14:10  YxinHaaa  阅读(1)  评论(0编辑  收藏  举报