📄 e317. parsing the time using a custom format.txt
字号:
A pattern of special characters is used to specify the format of the time to parse. The same set of pattern characters are used to parse times. See e316 Formatting the Time Using a Custom Format for a listing of some pattern characters.
Note: This example formats dates using the default locale (which, in the author's case, is Locale.ENGLISH). If the example is run in a different locale, the text (e.g., month names) will not be the same.
try {
// Some examples
DateFormat formatter = new SimpleDateFormat("hh.mm.ss a");
Date date = (Date)formatter.parse("02.36.33 PM");
formatter = new SimpleDateFormat("HH:mm:ss Z");
date = (Date)formatter.parse("22:14:02 -0500");
} catch (ParseException e) {
}
Related Examples
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -