当前位置:网站首页>Time tools
Time tools
2022-07-05 11:57:00 【asahi_ xin】
@SuppressLint({
"SimpleDateFormat"})
public class TimeUtils {
public static String COMPLETE_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
public static String DATE_FORMAT = "yyyy-MM-dd";
public static String TIME_FORMAT = "HH:mm:ss";
/** * Get the current time String type * * @return Time */
public static String getStringDate(String format) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
Date date = new Date(System.currentTimeMillis());
return simpleDateFormat.format(date);
}
/** * Get the current time long type * * @return Time */
public static long getLongDate() {
return System.currentTimeMillis();
}
/** * long Type time is converted to string * * @param time Time to be converted * @return Conversion time */
public static String formatTime(String format, long time) {
SimpleDateFormat df = new SimpleDateFormat(format);
return df.format(new Date(time));
}
/** * Calculate the number of days between two dates * * @param startDate Starting time * @param endDate End time * @return Days */
public static long getDateDistance(String startDate, String endDate) {
Date newStartDate = null;
Date newEndDate = null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
try {
newStartDate = simpleDateFormat.parse(startDate);
newEndDate = simpleDateFormat.parse(endDate);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar startInstance = Calendar.getInstance();
startInstance.setTime(newStartDate);
Calendar endInstance = Calendar.getInstance();
endInstance.setTime(newEndDate);
return (endInstance.getTimeInMillis() - startInstance.getTimeInMillis()) / (1000 * 3600 * 24);
}
/** * Calculate the date minus the time difference * * @param day date * @param num Time difference * @return Calculate the date */
public static String getDateDistance(String day, int num) {
Date newDate;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
try {
newDate = simpleDateFormat.parse(day);
Date distance = new Date(newDate.getTime() - (long) num * 24 * 60 * 60 * 1000);
return simpleDateFormat.format(distance);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}
边栏推荐
猜你喜欢
12. (map data) cesium city building map
Redis master-slave mode
1 plug-in to handle advertisements in web pages
yolov5目标检测神经网络——损失函数计算原理
redis主从中的Master自动选举之Sentinel哨兵机制
调查显示传统数据安全工具在60%情况下无法抵御勒索软件攻击
【 YOLOv3中Loss部分计算】
【云原生 | Kubernetes篇】Ingress案例实战(十三)
COMSOL -- three-dimensional graphics random drawing -- rotation
The survey shows that traditional data security tools cannot resist blackmail software attacks in 60% of cases
随机推荐
SET XACT_ ABORT ON
COMSOL -- establishment of 3D graphics
Unity Xlua MonoProxy Mono代理类
[crawler] Charles unknown error
Unity xlua monoproxy mono proxy class
yolov5目標檢測神經網絡——損失函數計算原理
多表操作-子查询
13. (map data) conversion between Baidu coordinate (bd09), national survey of China coordinate (Mars coordinate, gcj02), and WGS84 coordinate system
ACID事务理论
【上采样方式-OpenCV插值】
HiEngine:可媲美本地的云原生内存数据库引擎
12.(地图数据篇)cesium城市建筑物贴图
【yolov5.yaml解析】
[yolov3 loss function]
Splunk configuration 163 mailbox alarm
Multi table operation - sub query
[calculation of loss in yolov3]
Web API configuration custom route
1 plug-in to handle advertisements in web pages
Redis集群(主从)脑裂及解决方案