当前位置:网站首页>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
边栏推荐
- 刚购买了一个MYSQL数据库,提示已有实例,控制台登录实例要提供数据库账号,我如何知道数据库账号。
- Smooth live broadcast | analysis of key technologies for live broadcast pain points
- Coinbase will launch the first encryption derivative for individual investors
- 顺序表的基本操作
- Sequence stack version 1.0
- 海泰前沿技术|隐私计算技术在医疗数据保护中的应用
- Map跟object 的区别
- When querying the database with Gorm, reflect: reflect flag. mustBeAssignable using unaddressable value
- opds sql组件能不能将流程参数通过上下文传给下一个组件
- Design of routing service for multi Activity Architecture Design
猜你喜欢

主数据建设的背景

The Network Security Review Office launched a network security review on HowNet, saying that it "has a large amount of important data and sensitive information"

Summary of idea practical skills: how to rename a project or module to completely solve all the problems you encounter that do not work. It is suggested that the five-star collection be your daughter

Procedural life: a few things you should know when entering the workplace

物聯網?快來看 Arduino 上雲啦

Apple doesn't need money, but it has no confidence in its content

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

Cooking business experience of young people: bloggers are busy selling classes and bringing goods, and the organization earns millions a month

Visitor model -- generation gap between young and middle-aged people

苹果不差钱,但做内容“没底气”
随机推荐
Basic operation of sequence table
浅谈MySql update会锁定哪些范围的数据
伯克利、MIT、劍橋、DeepMind等業內大佬線上講座:邁向安全可靠可控的AI
Postman assertion
Berkeley, MIT, Cambridge, deepmind and other industry leaders' online lectures: towards safe, reliable and controllable AI
对“宁王”边卖边买,高瓴资本“高抛低吸”已套现数十亿
Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading
伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI
Steps of JMeter performance test
How to enhance influence
Jd.com: how does redis implement inventory deduction? How to prevent oversold?
Bytebase加入阿里云PolarDB开源数据库社区
Wechat applet custom tabbar
2022年最新四川建筑八大员(电气施工员)模拟题库及答案
字节、腾讯也下场,这门「月赚3000万」的生意有多香?
Internet of things? Come and see Arduino on the cloud
开放可编程基础设施(OPI)项目,重新定义DPU/IPU
物聯網?快來看 Arduino 上雲啦
Undo log and redo log must be clear this time
Material management system based on SSM (source code + document + database)