您的位置 首页 java

java学习:Java中的时间类

各位小伙伴

娜娜又来给大家分享知识点了

今天我们来分享 Java

那些表示时间的类

Date类

Date类的概述

类 Date 表示特定的瞬间,精确到毫秒。

构造方法

public Date()

获取当前的时间

public Date(long date)

如果参数为零则时间为1970年1月1号

成员方法

public long getTime()

public void setTime(long time)

SimpleDateFormat类

DateFormat类的概述(SimpleDateFormat类的父类)

DateFormat 是日期/时间格式化子类的 抽象类 ,它以与语言无关的方式格式化并解析日期或时间。是抽象类,所以使用其子类SimpleDateFormat( SimpleDateFormat 类可以实现日期和 字符串 的相互转换)

SimpleDateFormat构造方法

public SimpleDateFormat()

public SimpleDateFormat(String pattern)

public Date parse(String source)

把字符串转换成对象~

Calendar类

Calendar类的概述

Calendar 类是一个抽象类,它为特定瞬间与一组诸如 YEAR、MONTH、DAY_OF_MONTH、HOUR 等日历字段之间的转换提供了一些方法,并为操作日历字段(例如获得下星期的日期)提供了一些方法。

成员方法

public static Calendar getInstance()

public int get(int field)

直接输出c会打印出很多东西看起来不方便

我们可以用get方法来获取我们想要的内容

public void add(int field,int amount)

对指定字段进行增加或减少的操作

public final void set(int year,int month,int date)

修改指定字段

呼~

在Java中的那些有关于时间类

就到这了

伙伴们再见了

我是萌新娜娜

立志做一个不翻车的老司机

学习Java的路上请多多指教

文章来源:智云一二三科技

文章标题:java学习:Java中的时间类

文章地址:https://www.zhihuclub.com/182226.shtml

关于作者: 智云科技

热门文章

网站地图