当前位置:网站首页>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
边栏推荐
- Intranet Security Learning (V) -- domain horizontal: SPN & RDP & Cobalt strike
- Leetcode 450 deleting nodes in a binary search tree
- Room cannot create an SQLite connection to verify the queries
- PV static creation and dynamic creation
- Chapter 16 oauth2authorizationrequestredirectwebfilter source code analysis
- Notepad++ regular expression replacement string
- Start from the bottom structure and learn the introduction of fpga---fifo IP core and its key parameters
- 行列式学习笔记(一)
- Tools to improve work efficiency: the idea of SQL batch generation tools
- Shardingsphere source code analysis
猜你喜欢

Knowledge about the memory size occupied by the structure

建立时间和保持时间的模型分析

STM32 configuration after chip replacement and possible errors

Classic CTF topic about FTP protocol

【DesignMode】组合模式(composite mode)

数据库遇到的问题

【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)

Key structure of ffmpeg - avframe

Classical concurrency problem: the dining problem of philosophers

Multithreading and high concurrency (8) -- summarize AQS shared lock from countdownlatch (punch in for the third anniversary)
随机推荐
Key structure of ffmpeg -- AVCodecContext
Yunna | what are the main operating processes of the fixed assets management system
【DesignMode】适配器模式(adapter pattern)
[binary search tree] add, delete, modify and query function code implementation
Hudi of data Lake (1): introduction to Hudi
Multithreading and high concurrency (8) -- summarize AQS shared lock from countdownlatch (punch in for the third anniversary)
Hardware and interface learning summary
数据分析思维分析方法和业务知识——分析方法(三)
What is information security? What is included? What is the difference with network security?
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
JS 这次真的可以禁止常量修改了!
Knowledge about the memory size occupied by the structure
Tools to improve work efficiency: the idea of SQL batch generation tools
剖面测量之提取剖面数据
uniapp开发,打包成H5部署到服务器
Permission problem: source bash_ profile permission denied
Wechat applet -- wxml template syntax (with notes)
[Chongqing Guangdong education] reference materials for Zhengzhou Vocational College of finance, taxation and finance to play around the E-era
Detailed explanation of APP functions of door-to-door appointment service
常用API类及异常体系