当前位置:网站首页>SimpleDateFormat 格式化和解析日期的具体类
SimpleDateFormat 格式化和解析日期的具体类
2022-06-24 19:42:00 【程序员久安】
SimpleDateFormat 格式化和解析日期的具体类

SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
日期转字符串
y 代表年 M 代表月 d 代表日 E 代表星期 H 代表24进制的小时 h 代表12进制的小时
m 代表分钟 s 代表秒 (大写的)S 代表毫秒
//把日期格式化文本
String format = sdf.format(date);
System.out.println(format);//2021年05月26日 16时23分01秒
//把字符串解析为Date时间
Date parse = sdf.parse("2021年05月26日 16时07分25秒");
System.out.println(parse);//Wed May 26 16:07:25 CST 2021

Date date1 = new Date();
//判断当前时间是否在设定时间之间或者之后
boolean after = date1.after(parse);
System.out.println("当前时间在设定时间之后:"+after);
boolean before = date1.before(parse);
System.out.println("当前时间在设定时间之前:"+before);
边栏推荐
- Spark 离线开发框架设计与实现
- Financial management [2]
- Construction equipment [5]
- EMI的主要原因-工模电流
- [postgraduate entrance examination English] prepare for 2023, learn list9 words
- Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!
- Do you need to improve your code reading ability? It's a trick
- Use of laravel verifier
- Getting started with the go Cobra command line tool
- [Wuhan University] information sharing of the first and second postgraduate entrance examinations
猜你喜欢

23研考生注意啦!备考期间最容易中招的骗局,居然是它们?!

【js】-【字符串-应用】- 学习笔记
Paddledtx v1.0 has been released, and its security and flexibility have been comprehensively improved!

从客户端到服务器

Concurrent shared model management

Main cause of EMI - mold current

【js】-【數組、棧、隊列、鏈錶基礎】-筆記

03_ Spingboot core profile

Servlet
Mycms we media CMS V3.0, resource push optimization, new free template
随机推荐
数字IC设计经验整理(二)
Epics record reference 3 -- fields common to all records
Financial management [5]
【js】-【栈、队-应用】-学习笔记
Laravel study notes
Recommended course: workplace writing training
Building Survey [2]
Research Report on market supply and demand and strategy of China's solar charging controller industry
Super detailed cookie addition, deletion, modification and query
推送Markdown格式信息到钉钉机器人
websocket学习
Laravel authentication module auth
C#学习两年的增删改查和C#导入导出(去重)案例
【武汉大学】考研初试复试资料分享
[ROS play with turtle turtle]
laravel 创建 service层
EPICS记录参考2--EPICS过程数据库概念
Docker installation MySQL simple without pit
剑指 Offer 42. 连续子数组的最大和
Canvas to add watermark to pictures