如何以编程方式从存储在字符串中的日期创建模式? [英] How Would You Programmatically Create a Pattern from a Date that is Stored in a String?

查看:92
本文介绍了如何以编程方式从存储在字符串中的日期创建模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含日期表示的字符串。看起来像:



星期四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屋!

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