如何在java中将String转换为Date [英] How to convert String to Date in java
本文介绍了如何在java中将String转换为Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类似日期月份的字符串(2012年8月31日)。我想将其转换为日期格式。
I have a string something like date month year(31 08 2012) . I want to convert it to date format.
String string = "31082012";
Date date = new SimpleDateFormat("DDMMYYYY").parse(string);
System.out.println(date);
推荐答案
首先,你的格式错了,它应该是 ddMMyyyy
Firstly, Your format is wrong, it should be ddMMyyyy
Date date = new SimpleDateFormat("ddMMyyyy").parse(string);
这篇关于如何在java中将String转换为Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文