当前位置:网站首页>时间相关-格式、运算、比较、转换
时间相关-格式、运算、比较、转换
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");
}
边栏推荐
- Room第一次使用
- Multipass Chinese document - Overview
- 【无标题】测试下啊
- 微信小程序实现OCR扫描识别
- 阿里云配置SLB(负载均衡)实例
- Kwai handled more than 54000 illegal accounts: how to crack down on illegal accounts on the platform
- What is MYCAT? Get to know you quickly
- 海贼oj#146.字符串
- Golang中的深拷贝与浅拷贝
- [network planning] 2.5 brief introduction to P2P architecture
猜你喜欢
![[network counting] 1.4 network delay, packet loss and throughput](/img/a8/74a1b44ce4d8b0b1a85043a091a91d.jpg)
[network counting] 1.4 network delay, packet loss and throughput
![[MVC&Core]ASP. Introduction to net core MVC view value transfer](/img/c2/3e69cda2fed396505b5aa5888b9e5f.png)
[MVC&Core]ASP. Introduction to net core MVC view value transfer

What is MYCAT? Get to know you quickly

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

Dictionary sort of array

阻塞隊列 — DelayedWorkQueue源碼分析

Dynamic programming classical topic triangle shortest path

SLAM卡尔曼滤波&&非线性优化

What is the difference between hubs, switches and routers?
![[network planning] 3.2 transport layer - UDP: connectionless service](/img/a8/74a1b44ce4d8b0b1a85043a091a91d.jpg)
[network planning] 3.2 transport layer - UDP: connectionless service
随机推荐
安全培训管理办法
[network planning] 1.3 packet switching and circuit switching in the network core
Qt线程与界面
Using solrj to add, delete, modify, and query Solr is too simple
Multipass Chinese document - Overview
The driver has not received any packets from the server
Download Google gcr IO image
富文本活动测试1
RPC details
[untitled]
f‘s‘f‘s‘f‘s‘d
Signature verification failed during system application installation
Fastdfs quick start
array_ column() expects parameter 1 to be array, array given
Dictionary sort of array
Baidu PaddlePaddle paddlepaddle latest series AI course playback address
Safety training management measures
teterttet
ts+fetch实现选择文件上传
The principle and source code interpretation of executor thread pool in concurrent programming