当前位置:网站首页>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
边栏推荐
- Single source shortest path exercise (I)
- Extracting profile data from profile measurement
- Ffmpeg learning - core module
- Gd32f4xx UIP protocol stack migration record
- 什么叫做信息安全?包含哪些内容?与网络安全有什么区别?
- 认识提取与显示梅尔谱图的小实验(观察不同y_axis和x_axis的区别)
- Search (DFS and BFS)
- LeetCode 6006. Take out the least number of magic beans
- Key structure of ffmpeg - avformatcontext
- How to solve the problems caused by the import process of ecology9.0
猜你喜欢
Atcoder beginer contest 254 [VP record]
notepad++正则表达式替换字符串
Room cannot create an SQLite connection to verify the queries
FFmpeg抓取RTSP图像进行图像分析
Priority queue (heap)
单商户V4.4,初心未变,实力依旧!
Mathematical model Lotka Volterra
[noi simulation] Anaid's tree (Mobius inversion, exponential generating function, Ehrlich sieve, virtual tree)
Location based mobile terminal network video exploration app system documents + foreign language translation and original text + guidance records (8 weeks) + PPT + review + project source code
Start from the bottom structure and learn the introduction of fpga---fifo IP core and its key parameters
随机推荐
FFMPEG关键结构体——AVCodecContext
Solve the problem of reading Chinese garbled code in sqlserver connection database
[noi simulation] Anaid's tree (Mobius inversion, exponential generating function, Ehrlich sieve, virtual tree)
云呐|固定资产管理系统主要操作流程有哪些
MySQL functions
There is no network after configuring the agent by capturing packets with Fiddler mobile phones
LeetCode 6005. The minimum operand to make an array an alternating array
AtCoder Beginner Contest 258【比赛记录】
7.5 decorator
Classic CTF topic about FTP protocol
What are the functions of Yunna fixed assets management system?
STM32 configuration after chip replacement and possible errors
The difference of time zone and the time library of go language
【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)
uniapp开发,打包成H5部署到服务器
MySQL存储引擎
Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4
Global and Chinese markets of POM plastic gears 2022-2028: Research Report on technology, participants, trends, market size and share
Single merchant v4.4 has the same original intention and strength!
notepad++正則錶達式替換字符串