1、将OffsetDateTime转为Date类型
Date.from(CAFxxx.current.getCurrentDateTime().toInstant());
2、 /**
* 对指定的date对象进行格式化:yyyy-MM-dd HH:mm:ss
* @param date
* @return
*/
public static String formateDateTime(Date date){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dataStr = sdf.format(date);
return dataStr;
}
3、 /**
* 对指定的date对象进行格式化:yyyy-MM-dd
* @param date
* @return
*/
public static String formateDate(Date date){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dataStr = sdf.format(date);
return dataStr;
}
4、/**
* 对指定的date对象进行格式化:yyyy-MM-dd HH:mm:ss
* @param date
* @return
*/
public static String formateTime(Date date){
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String dataStr = sdf.format(date);
return dataStr;
}
5、/**
* @param startDate 开始时间
* @param endDate 结束时间
* @return 两个时间之差的总小时数/总天数【带两位小数】
*/
public static Map getDifferHourAndDay(Date startDate, Date endDate) {
Map<String,Double> map = new HashMap<>();
long times = endDate.getTime() - startDate.getTime();
double hours = (double) times/(60*60*1000);
long day = endDate.getDay()-startDate.getDay();
double days = (double) day/(1000 * 24 * 60 * 60);
BigDecimal h= BigDecimal.valueOf(hours);
BigDecimal d= BigDecimal.valueOf(days);
double waitHours = h.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
double waitDay = d.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
map.put("waitHours",waitHours);
map.put("waitDay",waitDay);
return map;
}
6、 /**
* @return 今天是本月的第几天
*/
public static int getDayOfMoon(){
Calendar calendar = Calendar.getInstance();
Date today = Date.from(CAFxxx.current.getCurrentDateTime().toInstant());
calendar.setTime(today);// 此处可换为具体某一时间
int monthDay = calendar.get(Calendar.DAY_OF_MONTH);
return monthDay;
}
7、/**
*
* @return 今天是星期几
*/
public static int getDayOfWeek(){
Calendar calendar = Calendar.getInstance();
Date today = Date.from(CAFxxx.current.getCurrentDateTime().toInstant());
calendar.setTime(today);// 此处可换为具体某一时间
int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
if (weekDay == 1) {
weekDay = 7;
} else {
weekDay = weekDay - 1;
}
return weekDay;
}
8、/**
*
* @param date
* @return 返回指定月的天数[本月共有几天]
*/
public static int getDaysOfMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
}
9、/**
*
* @return 返回当前的小时(int型 0-23)及分钟数(0-59)
*/
public static Map getHourAndMinOfDay(){
Map<String,String> map = new HashMap<>();
Date date = Date.from(CAFxxx.current.getCurrentDateTime().toInstant());
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
map.put("hour",String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)));
map.put("minute", String.valueOf(calendar.get(Calendar.MINUTE)));
map.put("timeDate",formateDateTime(date));
return map;
}
10、向Oracle插入当前时间:
sysdate为当前机器时间
对于insert或者update语句,需要将当前时间赋值到字段中,可以使用如下函数:
to_timestamp(to_char(sysdate,'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS')
TO_TIMESTAMP(#{yqrq}, 'YYYY-MM-DD HH24:MI:SS')
11、public static String dateToString(Date date) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
return format.format(date);
}
12、public static Date string2UDate(String str) {
Date date = null;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
date = format.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
13、// 获取指定日期的前一天
public static String getDayBefore(String specifiedDay){
Calendar c = Calendar.getInstance();
Date date = null;
try {
date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
} catch (ParseException e) {
e.printStackTrace();
}
c.setTime(date);
int day = c.get(Calendar.DATE);
c.set(Calendar.DATE, day - 1);
String dayAfter = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
return dayAfter;
}
14、// 获取指定日期的前一天
public static Date getDateBefore(Date specifiedDate){
String specifiedDay = dateToString(specifiedDate);
Calendar c = Calendar.getInstance();
Date date = null;
try {
date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
} catch (ParseException e) {
e.printStackTrace();
}
c.setTime(date);
int day = c.get(Calendar.DATE);
c.set(Calendar.DATE, day - 1);
String dayAfter = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
return string2UDate(dayAfter);
}
15、// 获取指定日期的后一天
public static String getDayAfter(String specifiedDay) {
Calendar c = Calendar.getInstance();
Date date = null;
try {
date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
} catch (ParseException e) {
e.printStackTrace();
}
c.setTime(date);
int day = c.get(Calendar.DATE);
c.set(Calendar.DATE, day + 1);
String dayAfter = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
return dayAfter;
}
16、// 获取指定日期的后一天
public static Date getDateAfter(Date specifiedDate) {
String specifiedDay = dateToString(specifiedDate);
Calendar c = Calendar.getInstance();
Date date = null;
try {
date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
} catch (ParseException e) {
e.printStackTrace();
}
c.setTime(date);
int day = c.get(Calendar.DATE);
c.set(Calendar.DATE, day + 1);
String dayAfter = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
return string2UDate(dayAfter);
}
17、// 日期去掉时分秒
public static Date dateRemoveHMS(Date date){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String str = format.format(date);
Date returnDate = null;
try {
returnDate = format.parse(str);
}catch (ParseException e){
throw new RuntimeException("Date去除时分秒转换失败");
}
return returnDate;
}
18、// Date 转换为 TimeStamp
public static Timestamp date2Timestamp(Date date){
return new Timestamp(date.getTime());
}
19、/**
* 计算日期天数差
*/
public static Integer daysDiff(Date startDate, Date endDate) {
Temporal temporal1 = startDate.toInstant();
Temporal temporal2 = endDate.toInstant();
long daysDiff = ChronoUnit.DAYS.between(temporal1, temporal2);
return (Integer) (int) daysDiff;
}
20、分组后,字段连接:
postgresql:string_agg('字段名',',');
mysql:group_concat(DISTINCT v
ORDER BY v ASC
SEPARATOR ',');
21、前台生成UUID:
const getuuid = () => {
debugger;
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4";
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
s[8] = s[13] = s[18] = s[23] = "-";
var uuid = s.join("");
return uuid
}
22、
1)、首先找到一个能够正常使用重置试用天数插件(reset插件)的该公司系列的工具,例如pycharm
2)、以pycharm为例,使用Everything搜索evaluation.key,找到pycharm对应的key,
例如:PyCharm192.evaluation.key
3)、找到IDEA版本对应的key,例如:idea212.evaluation.key
4)、将PyCharm192.evaluation.key复制到IDEA的idea212.evaluation.key所在的文件夹,
并将PyCharm192.evaluation.key的名称改为idea212.evaluation.key
5)、此时,重新打开IDEA,就能够正常使用了
23、远程桌面连接弹出“出现身份验证错误,要求的函数不受支持”
https://zhuanlan.zhihu.com/p/546726049?utm_id=0
记录......
于 2022-09-02 11:10:42 首次发布
这篇博客汇总了Java中关于日期时间的处理方法,包括OffsetDateTime转Date、日期格式化、时间差计算、获取当前月天数、星期等。还涉及Oracle数据库中时间插入以及日期加减操作,以及UUID生成。此外,还介绍了如何重置某些工具的试用天数。
摘要由CSDN通过智能技术生成