当前位置:网站首页>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;
}
}
边栏推荐
- Open3d European clustering
- Multi table operation - Auto Association query
- Programmers are involved and maintain industry competitiveness
- Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in
- [leetcode] wild card matching
- [pytorch modifies the pre training model: there is little difference between the measured loading pre training model and the random initialization of the model]
- C # implements WinForm DataGridView control to support overlay data binding
- 11.(地图数据篇)OSM数据如何下载使用
- POJ 3176 cow bowling (DP | memory search)
- COMSOL -- establishment of geometric model -- establishment of two-dimensional graphics
猜你喜欢
1个插件搞定网页中的广告
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
【PyTorch预训练模型修改、增删特定层】
codeforces每日5题(均1700)-第五天
1 plug-in to handle advertisements in web pages
Redis集群(主从)脑裂及解决方案
yolov5目標檢測神經網絡——損失函數計算原理
Cdga | six principles that data governance has to adhere to
XML parsing
idea设置打开文件窗口个数
随机推荐
Liunx prohibit Ping explain the different usage of traceroute
Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in
13. (map data) conversion between Baidu coordinate (bd09), national survey of China coordinate (Mars coordinate, gcj02), and WGS84 coordinate system
[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
Proof of the thinking of Hanoi Tower problem
The survey shows that traditional data security tools cannot resist blackmail software attacks in 60% of cases
查看多台机器所有进程
【L1、L2、smooth L1三类损失函数】
Redis集群的重定向
Codeworks 5 questions per day (1700 average) - day 5
调查显示传统数据安全工具在60%情况下无法抵御勒索软件攻击
【Win11 多用户同时登录远程桌面配置方法】
Mongodb replica set
ACID事务理论
JS for循环 循环次数异常
Ncp1342 chip substitute pn8213 65W gallium nitride charger scheme
Codeforces Round #804 (Div. 2)
Empêcher le navigateur de reculer
COMSOL -- establishment of 3D graphics
yolov5目標檢測神經網絡——損失函數計算原理