代码如下:
package com.wy.test.other;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 时间的工具类
* 1.获取系统当前时间(年月日 时分秒)(12小时制);
* 2.获取系统当前时间(年月日 时分秒)(24小时制);
* 3.系统当前时间(年月日)
*/
public class DateUtil {
/**
* 获取系统当前时间(12小时制)
* 区别:12小时制使用小写的hh,24小时制使用大写的HH
* @return 系统当前时间(年月日 时分秒)
*/
public static String getCurrent12DateTotal() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String date = simpleDateFormat.format(new Date());
return date;
}
/**
* 获取系统当前时间(24小时制)
* 区别:12小时制使用小写的hh,24小时制使用大写的HH
* @return 系统当前时间(年月日 时分秒)
*/
public static String getCurrent24DateTotal() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = simpleDateFormat.format(new Date());
return date;
}
/**
* 获取系统当前时间
* @return 系统当前时间(年月日)
*/
public static String getCurrentDateHalf() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String date = simpleDateFormat.format(new Date());
return date;
}
}
在项目中的应用:
//12小时制年月日时分秒
String current12DateTotal = DateUtil.getCurrent12DateTotal();
//24小时制年月日时分秒
String current24DateTotal = DateUtil.getCurrent24DateTotal();
//年月日
String currentDateHalf = DateUtil.getCurrentDateHalf();
早计划,早准备,早完成。 欢迎关注!交流!Star!
GitHub:https://github.com/wangyang0313
微信公众号:一个灵活的胖子MrWang
CSDN:https://blog.csdn.net/qq941263013
20200430145304899.jpg