当前位置:网站首页>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;
}
}
边栏推荐
- JS for循环 循环次数异常
- liunx禁ping 详解traceroute的不同用法
- 1 plug-in to handle advertisements in web pages
- pytorch-线性回归
- SET XACT_ ABORT ON
- The solution of outputting 64 bits from printf format%lld of cross platform (32bit and 64bit)
- Hash tag usage in redis cluster
- Principle of persistence mechanism of redis
- Unity xlua monoproxy mono proxy class
- Principle of redis cluster mode
猜你喜欢

报错ModuleNotFoundError: No module named ‘cv2.aruco‘
![[cloud native | kubernetes] actual battle of ingress case (13)](/img/1a/9404f6dcedd15827fa45f8f6f4c093.png)
[cloud native | kubernetes] actual battle of ingress case (13)

《增长黑客》阅读笔记

abap查表程序

iTOP-3568开发板NPU使用安装RKNN Toolkit Lite2

【云原生 | Kubernetes篇】Ingress案例实战(十三)

COMSOL -- 3D casual painting -- sweeping

idea设置打开文件窗口个数
你做自动化测试为什么总是失败?

Wireless WiFi learning 8-channel transmitting remote control module
随机推荐
splunk配置163邮箱告警
【云原生 | Kubernetes篇】Ingress案例实战(十三)
Pytorch weight decay and dropout
Redis cluster (master-slave) brain crack and solution
Wireless WiFi learning 8-channel transmitting remote control module
[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
网络五连鞭
【主流Nivida显卡深度学习/强化学习/AI算力汇总】
互联网公司实习岗位选择与简易版职业发展规划
【使用TensorRT通过ONNX部署Pytorch项目】
Mysql统计技巧:ON DUPLICATE KEY UPDATE用法
调查显示传统数据安全工具在60%情况下无法抵御勒索软件攻击
Mmclassification training custom data
[loss functions of L1, L2 and smooth L1]
一次生产环境redis内存占用居高不下问题排查
Open3D 网格(曲面)赋色
Principle of redis cluster mode
【SingleShotMultiBoxDetector(SSD,单步多框目标检测)】
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
Programmers are involved and maintain industry competitiveness