当前位置:网站首页>Problems and solutions of converting date into specified string in date class
Problems and solutions of converting date into specified string in date class
2022-07-06 00:22:00 【Wang Xiaoya】
I'm learning Date Follow the exercise as you read the content , The result is always wrong , I think the code is right, duck , Is it because my bag is incorrect ,
Check the code again and again to make sure the code is ok , What's the problem ? I fell into silence ……
Fortunately, with the blessing of my eyes, I finally found , above 11:20:00 Colon of English input method used , The following hours, minutes and seconds use the colon of the Chinese input method , Nature cannot match , Dates and patterns must be compared one by one
After correcting it into English input method, it is compiled and run successfully
sdf2.parse(ss); Quick completion Ctrl+lt+v
//ParseException Report errors , Parsing exceptions Shortcut keys for solving Alt+Enter, Default first
Attach complete code :
package com.com.object_11.APITest_01.Date;
// Toxic poison
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/*SimpleDateFormat Class constructor
public SimpleDateFormat() Construct a SimpleDateFormat, Use default mode and date format
public SimpleDateFormat(String pattern) Construct a SimpleDateFormat Use the given pattern and default date format
- SimpleDateFormat Common methods of class
- format ( from Date To String)
- public final String format(Date date): Format the date as a date / Time string
- analysis ( from String To Date)
- public Date parse(String source): Parse the text from the beginning of the given string to generate the date */
public class SimpleDateFormatDemo {
public static void main(String[] args) throws ParseException {
// format ( from Date To String)
// Parameterless construction creates objects
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(); // No arguments structure
// How to create sdf.format(d); then Ctrl+Alt+v Automatic generation
String s = sdf.format(d);
// Output this string
System.out.println(s);
//2022/6/29 In the morning 11:03 ( Default mode )
System.out.println("-----------");
// format ( from Date To String)
// Parameterless construction creates objects
Date d1 = new Date();
// SimpleDateFormat sdf = new SimpleDateFormat();
// Remove the nonparametric structure , Write it yourself
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy year MM month dd Japan HH:mm:ss"); // Mm / DD / yyyy HHM / S
// How to create sdf.format(d1); then Ctrl+Alt+v Automatic generation
String s1 = sdf.format(d1);
// Output this string
System.out.println(s1);
// ( Default mode )
System.out.println("-----------");
// ( from String To Date)
String ss = "2025-06-29 11:20:00";
//ParseException Report errors , Parsing exceptions
// SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy year MM month dd Japan HH:mm:ss");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dd = sdf2.parse(ss);
System.out.println(dd);
}
}
//2022/6/30 Afternoon 5:00
//-----------
//2022/6/30 Afternoon 5:00
//-----------
//Sun Jun 29 11:20:00 CST 2025
边栏推荐
- The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
- What are the functions of Yunna fixed assets management system?
- What are Yunna's fixed asset management systems?
- Global and Chinese markets of POM plastic gears 2022-2028: Research Report on technology, participants, trends, market size and share
- Hudi of data Lake (1): introduction to Hudi
- Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]
- Notepad++ regular expression replacement string
- 云呐|固定资产管理系统功能包括哪些?
- 多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
- [binary search tree] add, delete, modify and query function code implementation
猜你喜欢
如何解决ecology9.0执行导入流程流程产生的问题
Key structure of ffmpeg - avframe
Mathematical model Lotka Volterra
How much do you know about the bank deposit business that software test engineers must know?
【DesignMode】装饰者模式(Decorator pattern)
MySQL之函数
关于slmgr命令的那些事
Knowledge about the memory size occupied by the structure
建立时间和保持时间的模型分析
数据分析思维分析方法和业务知识——分析方法(三)
随机推荐
Yunna | what are the main operating processes of the fixed assets management system
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
How to solve the problems caused by the import process of ecology9.0
【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)
Codeforces round 804 (Div. 2) [competition record]
Classic CTF topic about FTP protocol
MySQL global lock and table lock
Permission problem: source bash_ profile permission denied
行列式学习笔记(一)
About the slmgr command
关于结构体所占内存大小知识
Room cannot create an SQLite connection to verify the queries
软件测试工程师必会的银行存款业务,你了解多少?
Key structure of ffmpeg - avformatcontext
STM32 configuration after chip replacement and possible errors
What are Yunna's fixed asset management systems?
Yolov5、Pycharm、Anaconda环境安装
Huawei equipment is configured with OSPF and BFD linkage
【DesignMode】组合模式(composite mode)
Solve the problem of reading Chinese garbled code in sqlserver connection database