Date formatting

zhaozj2021-02-12  155

Everyone will encounter some difficulties that are not difficult to use when using the Date object output date string. It is because he is not difficult because everyone is not doing, but it is only a common cumbersome conversion to make people worry, and most people are not taking into account. Some people may have aware of this, but may not be full, so I will write it here, I will give you a reference, I've been here to take a brick, I hope to have more people to discuss this topic. . There is a very useful class in Java: SimpleDateFormat, which uses template methods to format output date objects in text form. The general usage is as follows: SimpleDateFormat f = New SimpleDateFormat ("MMM DD, YYYY"); f.Format (new date ());

The string that constructs SimpleDateFormat is a mold. This mode is called

Model for "February 21th, 2004". Other modes definitions are: symbolic meaning display form

Example G AD text

ADY years

2001m month text or number

July or 07d day number

10h a.m./p.m. Matter hour (1 ~ 12) number

12h 24 hours clock (0 ~ 23) number

0M minute number

30S second number

43S miqi number

234E a few text

TuesdayD's first few days in the year

360F a few years in the month

The first few weeks in the year of 2W

The first few weeks of a month in 40W

1A a.m./p.m. Tag text

PMK 24 hour clock (1 ~ 24) number

24K a.m./p.m. Waves (0 ~ 11) numbers

0z Time Zone Text

EASTERN 'Essential Separator

'Single quaum symbol

'

These symbols can be combined, in which the display form is a symbol of "text", the long text string will be output using 4 or more repetitive combinations, and the short string is output.

Such as: E produces MON, while Eeee generates Monday. For symbols of the display form "text and numbers", the following two times include multiplexing generation numbers, and the text is generated twice.

转载请注明原文地址:https://www.9cbs.com/read-6317.html

New Post(0)