如何以编程方式从存储在字符串中的日期创建模式? [英] How Would You Programmatically Create a Pattern from a Date that is Stored in a String?
问题描述
星期四11月30日19:00:00 EST 2006
我试图使用SimpleDateFormat创建一个Date对象,并有2个问题。
1。)我无法弄清楚将解决方案硬编码到SimpleDateFormat构造函数中的模式
2。)我找不到一种方法,我可以使用API来解析字符串来确定模式,所以我可以重复使用这个日期输出的不同模式
如果有人知道使用API或定制解决方案的解决方案我将非常感激。
可以查看传递给SimpleDateFormat的格式 http://java.sun.com/javase /6/docs/api/java/text/SimpleDateFormat.html
new SimpleDateFormat(EEE MMM dd HH :mm:ss zzz yyyy)
至于你的第二个问题,我不知道Java库找出一个日期格式并解析它,而不需要提前知道什么格式。
I have a string that contains the representation of a date. It looks like:
Thu Nov 30 19:00:00 EST 2006
I'm trying to create a Date object using SimpleDateFormat and have 2 problems.
1.) I can't figure out the pattern to hard-code the solution into the SimpleDateFormat constructor
2.) I can't find a way I could parse the string using API to determine the pattern so I could reuse this for different patterns of date output
If anyone knows a solution using API or a custom solution I would greatly appreciate it.
The format to pass to SimpleDateFormat could be looked up at http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html
new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy")
As for your second question, I don't know of any Java library to figure out a date format and parse it without knowing in advance what the format is.
这篇关于如何以编程方式从存储在字符串中的日期创建模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!