如何将YY / MM / DD类型的字符串转换为java.util.Date? [英] How to convert string of type YY/MM/DD to java.util.Date?

查看:494
本文介绍了如何将YY / MM / DD类型的字符串转换为java.util.Date?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何将字符串转换成YY / MM格式的字符串(YY / MM / DD) MM / DD到 java.util.Date 。我可以使用 SimpleDateFormat / code>为此。

  String target =160211; 
DateFormat df = new SimpleDateFormat(yyMMdd,Locale.ENGLISH);
日期结果= df.parse(target);

有关更多选项和信息,您可以随时在这里查看完整的文档: http://docs.oracle.com/javase/8/docs/api/ java / text / SimpleDateFormat.html


I have searched but did not find the exact format(YY/MM/DD) for parsing the String.

How can I convert a string of type YY/MM/DD to java.util.Date. I have strings in the format "160310", "160211".

解决方案

You can use SimpleDateFormat for this.

String target = "160211";
DateFormat df = new SimpleDateFormat("yyMMdd", Locale.ENGLISH);
Date result =  df.parse(target);

For more options and info you can always checkout the full documentation about it here: http://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html

这篇关于如何将YY / MM / DD类型的字符串转换为java.util.Date?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆