In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use java time and date formatting, which is very detailed and has certain reference value. Friends who are interested must finish it!
An example of Java time formatting (formatting time through the format (date) method of the SimpleDateFormat class) is as follows:
Import java.text.SimpleDateFormat
Import java.util.Date
Public class FormatDateTest {
Public static void main (String [] args) {
String strDateForma = "yyyy-MM-dd HH:mm:ss"
SimpleDateFormat sdf = new SimpleDateFormat (strDateFormat)
System.out.println (sdf.format (new Date ()
}
} by running, the following results are obtained:
2019-04-19 09:15:29
At the same time, different results can be obtained according to different formats. The reference format is as follows:
Time format
Effect (for example)
Yyyy-MM-dd HH:mm:ss
2019-04-19 09:15:29
Yyyy-MM-dd
2019-04-19
HH:mm:ss
09:15:29
Yyyy/MM/dd
2019-04-19
Yy/m/d
19-4-19
...
...
Once you know the time formatting, you can customize the rules. Let's take a look at the meaning of the symbols in the rules, which are as follows:
Date and time symbol
Description
Y
That is, the meaning of Year (year). The two digits of the year identified by yy, such as 2019, means 19.
YYYY
As above, it means 4 digits. For example, 2019 is 2019.
M
That is, Month (month). Mm means to make up 0 before less than October, for example, June, it is 06; a single m is expressed as a changeable month, such as June as June and November as November.
D
That is, the meaning of Day (days). Dd indicates dissatisfaction with 10, filling bits with 0, such as 09 / 9 / d on the 9th, 09 / 19 on the 19th.
H
That is, Hour (hours), also divided into two kinds of variable digits and immutable digits, while the uppercase HH is 24-hour, and the lowercase hh is 12-hour.
M
That is, minute (minutes); distinguish between minutes and months by identifying whether m has a colon or not. it is also divided into two kinds of variable digits and immutable digits.
S
That is, Second (seconds), as above
The above is all the contents of the article "how to use java time and date format". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.