当前位置:网站首页>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
边栏推荐
- 如何解决ecology9.0执行导入流程流程产生的问题
- [designmode] adapter pattern
- LeetCode 1598. Folder operation log collector
- Wechat applet -- wxml template syntax (with notes)
- OS i/o devices and device controllers
- QT -- thread
- Multithreading and high concurrency (8) -- summarize AQS shared lock from countdownlatch (punch in for the third anniversary)
- Intranet Security Learning (V) -- domain horizontal: SPN & RDP & Cobalt strike
- DEJA_VU3D - Cesium功能集 之 055-国内外各厂商地图服务地址汇总说明
- 小程序技术优势与产业互联网相结合的分析
猜你喜欢
软件测试工程师必会的银行存款业务,你了解多少?
Room cannot create an SQLite connection to verify the queries
Classic CTF topic about FTP protocol
Configuring OSPF GR features for Huawei devices
关于结构体所占内存大小知识
Miaochai Weekly - 8
Room cannot create an SQLite connection to verify the queries
wx. Getlocation (object object) application method, latest version
Hudi of data Lake (1): introduction to Hudi
Priority queue (heap)
随机推荐
【在线聊天】原来微信小程序也能回复Facebook主页消息!
什么叫做信息安全?包含哪些内容?与网络安全有什么区别?
Configuring OSPF GR features for Huawei devices
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]
权限问题:source .bash_profile permission denied
Transport layer protocol ----- UDP protocol
MySQL global lock and table lock
【DesignMode】组合模式(composite mode)
Detailed explanation of APP functions of door-to-door appointment service
从底层结构开始学习FPGA----FIFO IP核及其关键参数介绍
Key structure of ffmpeg - avformatcontext
uniapp开发,打包成H5部署到服务器
Codeforces Round #804 (Div. 2)【比赛记录】
【DesignMode】装饰者模式(Decorator pattern)
云呐|固定资产管理系统功能包括哪些?
Classical concurrency problem: the dining problem of philosophers
FFMPEG关键结构体——AVFormatContext
FFT 学习笔记(自认为详细)
MySql——CRUD