当前位置:网站首页>时间相关-格式、运算、比较、转换
时间相关-格式、运算、比较、转换
2022-06-10 23:42:00 【灵丘丶白给王】
1、获取当前时间
Date currentDate = new Date();
2、转换成指定格式字符串
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String currentDateStr = df.format(currentDate);
3、获取一个时间的年、月、周、日
Calendar ca = Calendar.getInstance();
ca.setTime(currentDate);
int day = ca.get(Calendar.DAY_OF_YEAR);//一年中的第几天
int week = ca.get(Calendar.WEEK_OF_YEAR);//一年中的第几周
int month = ca.get(Calendar.MONTH)+1;//第几个月 8
int year = ca.get(Calendar.YEAR);//年份数值 2021
4、比较两个时间的大小
1)法一:用Date的getTime()函数获取时间的数值类型(long),然后像比较一个数一样比较两者的大小
Date date01 = new Date();
Date date02 = new Date();
if(date01.getTime() > date02.getTime()){
System.out.println("date01更大");
}else {
System.out.println("date02大于等于date01");
}
边栏推荐
- Random points in non overlapping rectangles
- The principle and source code interpretation of executor thread pool in concurrent programming
- array_ column() expects parameter 1 to be array, array given
- WIN11卸载小组件
- Multipass Chinese document - instructions for use (contents page)
- [network counting] 1.4 network delay, packet loss and throughput
- How to install mathtype6.9 and related problem solutions in office2016 (word2016)
- LeetCode 8. String to integer (ATOI) (medium, string)
- [no title] 4555
- [network planning] 2.1.1 brief introduction to client server system and P2P system
猜你喜欢

项目连接不到远程虚拟机The driver has not received any packets from the server.

【无标题】4555

Safety training management measures

安全培训管理办法

Fastdfs quick start

市值215亿,这个四川80后会让电视机成为历史?

Synchronized keyword for concurrent programming
![[network planning] 1.5 seven layer network model and five layer network model](/img/a8/74a1b44ce4d8b0b1a85043a091a91d.jpg)
[network planning] 1.5 seven layer network model and five layer network model

阻塞队列 — DelayedWorkQueue源码分析

unity 网格面片生成抛物线,折线
随机推荐
How about the CSC account of qiniu business school? Is it safe?
五大类型负载均衡的原理场景详解
Objects as points personal summary
WIN11卸载小组件
Go language channel understanding and use
Test it first
海贼oj#448.抽奖
Room第一次使用
项目连接不到远程虚拟机The driver has not received any packets from the server.
负载均衡策略图文详解
Safety training management measures
With a market value of 21.5 billion yuan, will the post-80s generation in Sichuan make TV history?
数组的字典排序
Kubeflow 1.2.0 installation
The principle and source code interpretation of executor thread pool in concurrent programming
Unity 容易被坑的点
Décomposition détaillée du problème de chemin le plus court du graphique
Block queue - delayedworkqueue Source Analysis
Learning notes: hook point of plug-in activity
JVM garbage collection mechanism and common garbage collectors