当前位置:网站首页>Format method and parse method of dateformat class
Format method and parse method of dateformat class
2022-06-24 20:57:00 【Platonic】
String format(Date date) | In the specified format , hold Date The date is converted to a string that matches the pattern . |
| parse(String obj) | Format the text as a date |
The following example demonstrates :
public class Demo03DataFormat {
public static void main(String[] args) throws ParseException {
// Use DateFormat Class format Method , Format the date as text
//String format(Date date) In the specified format , hold Date The date is converted to a string that matches the pattern
demo01();
System.out.println("================");// Split line
demo02();
}
public static void demo01(){
//1. establish SimpleDateFormat object , Pass the specified pattern in the constructor
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//2. call SimpleDateFormat Methods in objects format, According to the pattern specified by the constructor , hold Date The date is formatted as a pattern string /
Date date=new Date();
String format = sdf.format(date);
System.out.println(format);
System.out.println(date);
}
// Use DateFormat Class parse Method , Format the text as a date
public static void demo02() throws ParseException {
//1. establish SimpleDateFormat object , Pass the specified pattern in the constructor
SimpleDateFormat sdf=new SimpleDateFormat("yyyy year MM month dd Japan HH when mm branch ss second ");
//parse An error will be reported here , Two solutions :1. Use throws Throw an exception .2. Use try...catch... Handle
Date parse = sdf.parse("2022 year 01 month 22 Japan 16 when 34 branch 51 second ");
System.out.println(parse);
}
}
java.util.Date Two common methods
边栏推荐
- 基于SSM的物料管理系统(源码+文档+数据库)
- After idea installs these plug-ins, the code can be written to heaven. My little sister also has to arrange it
- Dx12 engine development course progress - where does this course go
- 开放可编程基础设施(OPI)项目,重新定义DPU/IPU
- 微信小程序自定义tabBar
- Jd.com: how does redis implement inventory deduction? How to prevent oversold?
- 刚购买了一个MYSQL数据库,提示已有实例,控制台登录实例要提供数据库账号,我如何知道数据库账号。
- Leetcode (146) - LRU cache
- Basic concepts and definitions of Graphs
- OpenVINO2022 Dev Tools安装与使用
猜你喜欢

“拯救”直播带货,一个董宇辉还不够

Grating diffraction

传统的IO存在什么问题?为什么引入零拷贝的?

红象云腾完成与龙蜥操作系统兼容适配,产品运行稳定

Difference between map and object

在Dialog中使用透明的【X】叉叉按钮图片

Behind Tiantian Jianbao storm: tens of millions in arrears, APP shutdown, and the founder's premeditated plan to run away?

Stackoverflow 年度报告 2022:开发者最喜爱的数据库是什么?

Combination mode -- stock speculation has been cut into leeks? Come and try this investment strategy!

The latest simulated question bank and answers of the eight members (Electrical constructors) of Sichuan architecture in 2022
随机推荐
苹果不差钱,但做内容“没底气”
在Dialog中使用透明的【X】叉叉按钮图片
Bytebase加入阿里云PolarDB开源数据库社区
Sequential stack traversal binary tree
The JS method parameter passed a number beginning with 0. A magical problem occurred and bothered me for a long time
A/B测试助力游戏业务增长
天天鉴宝暴雷背后:拖欠数千万、APP停摆,创始人预谋跑路?
Basic concepts and definitions of Graphs
网络安全审查办公室对知网启动网络安全审查
托管服务与SASE,纵享网络与安全融合 | 一期一会回顾
浅谈MySql update会锁定哪些范围的数据
Leetcode(455)——分发饼干
情绪识别AI竟「心怀鬼胎」,微软决定封杀它!
Haitai Advanced Technology | application of privacy computing technology in medical data protection
Otaku can't save yuan universe
I just purchased a MySQL database and prompted that there are already instances. The console login instance needs to provide a database account. How do I know the database account.
Popupwindow touch event transparent transmission scheme
[cloud resident co creation] ModelBox draws your own painting across the air
基于SSM的物料管理系统(源码+文档+数据库)
刚购买了一个MYSQL数据库,提示已有实例,控制台登录实例要提供数据库账号,我如何知道数据库账号。