我是Java新手,通常使用PHP.
我想转换这个字符串:
2011年3月14日星期四16:02:37 GMT
进入一个Calendar对象,这样我就可以像这样轻松地拉出Year和Month:
String yearAndMonth = cal.get(Calendar.YEAR)+cal.get(Calendar.MONTH);
Run Code Online (Sandbox Code Playgroud)
手动解析是不是一个坏主意?使用子字符串方法?
任何建议都会有所帮助!
如何将下面的日期字符串解析为Date对象?
String target = "Thu Sep 28 20:29:30 JST 2000";
DateFormat df = new SimpleDateFormat("E MM dd kk:mm:ss z yyyy");
Date result = df.parse(target);
Run Code Online (Sandbox Code Playgroud)
抛出异常......
java.text.ParseException: Unparseable date: "Thu Sep 28 20:29:30 JST 2000"
at java.text.DateFormat.parse(DateFormat.java:337)
Run Code Online (Sandbox Code Playgroud)