java calendar 时分秒_Java 通过 Calendar 获取独立的 年月日时分秒 代码封装

packagexingzhi.tools;importjava.text.DateFormat;importjava.text.ParseException;importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.Date;importjava.util.Locale;/*** 对象帮助类.

*@authorxingzhi 2020年4月28日 上午9:12:32

**/

public classDateHelper {/*** 日历对象

*@authorxingzhi 2020年6月5日 下午4:22:32*/

private staticCalendar cal;/*** 初始化日历对象.

*@authorxingzhi 2020年6月5日 上午9:16:27*/

private static voidInitial() {if(cal == null) {

cal=Calendar.getInstance();

}

}/*** 获取当前时间对象

*@authorxingzhi 2020年4月28日 下午9:11:54

*@return

*/

public staticDate GetCurrentDate() {

Date d= newDate();returnd;

}/*** 获取指定日期的年.

*@authorxingzhi 2020年6月5日 下午4:23:26

*@paramd

*@return

*/

public static intGetDateForYear(Date d) {

Initial();

cal.setTime(d);returncal.get(Calendar.YEAR);

}/*** 获取指定日期的月份

*@authorxingzhi 2020年6月5日 上午9:24:17

*@return返回一个整数表示的月份值.从0-11.*/

public static intGetDateForMonth(Date d) {

Initial();

cal.setTime(d);returncal.get(Calendar.MONTH);

}/*** 获取指定日期每月的天数.

*@authorxingzhi 2020年6月5日 上午9:29:58

*@paramd

*@return

*/

public static intGetDateForDay(Date d) {

Initial();

cal.setTime(d);returncal.get(Calendar.DATE);

}/*** 获取指定日期的小时数.

*@authorxingzhi 2020年6月5日 上午9:32:21

*@return

*/

public static intGetDateForHour(Date d) {

Initial();

cal.setTime(d);returncal.get(Calendar.HOUR);

}/*** 获取指定日期的分钟数.

*@authorxingzhi 2020年6月5日 上午9:32:21

*@return

*/

public static intGetDateForMinute(Date d) {

Initial();

cal.setTime(d);returncal.get(Calendar.MINUTE);

}/*** 获取指定日期的秒数.

*@authorxingzhi 2020年6月5日 上午9:32:21

*@return

*/

public static intGetDateForSecond(Date d) {

Initial();

cal.setTime(d);returncal.get(Calendar.SECOND);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值