yyyymmdd转换为 yyyy-mm-dd
时间: 2023-09-22 10:10:31 浏览: 112
要将yyyyMMdd转换为yyyy-MM-dd,可以使用Java的SimpleDateFormat类来实现。可以使用以下代码:
```java
String inputDate = "20211231";
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
String outputDate = outputFormat.format(inputFormat.parse(inputDate));
```
在这个代码中,我们首先定义了输入日期的格式为"yyyyMMdd",然后定义了输出日期的格式为"yyyy-MM-dd"。接下来,我们使用SimpleDateFormat的parse()方法将输入日期字符串解析为Date对象,并使用format()方法将解析后的Date对象格式化为输出日期字符串。最后,我们将输出日期字符串存储在outputDate变量中。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Java一行代码将yyyyMMdd转换为yyyy-MM-dd,yyyy-MM-dd转换为yyyyMMdd](https://blog.csdn.net/qq_38112624/article/details/128283702)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [【HQL实用】时间格式YYYYMMDD转换成YYYY-MM-DD](https://blog.csdn.net/u013631103/article/details/126983750)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文