从Java中日期字符串的未知格式返回日期格式 [英] Returning a date format from an unknown format of date string in java

查看:297
本文介绍了从Java中日期字符串的未知格式返回日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

解析Java中的任何日期

假设我们有一个字符串日期格式(用户未知)。可以从用户收到的可接受日期的示例:

Suppose we have a string of date in a format (unknown to the user). Examples of acceptable dates that you can receive from a user:


  • yyyy-MM-dd / yy-MM-dd

  • yyyy / MM / dd / yy / MM / dd

  • dd / MM / yyyy / dd / MM / yy

  • MM / dd / yyyy / MM / dd / yy`

  • yyyy-MM-dd/yy-MM-dd
  • yyyy/MM/dd/yy/MM/dd
  • dd/MM/yyyy/dd/MM/yy
  • MM/dd/yyyy/MM/dd/yy`

是否有一个接受字符串中日期的库并返回一个日期格式,可以由 SimpleDateFormat 或Joda Time使用?

Is there a library that accept a date in a string and returns a date format that can be used by SimpleDateFormat or Joda Time?

谢谢

推荐答案

作为一个简单的解决方案:我将在提供的输入中应用每种日期格式以获取Date对象,然后打印具有相同日期的Date对象格式。如果日期格式的输入和输出相同,则该日期格式为候选格式。

As a simple solution: I will apply each date format on the provided input to get a Date object , then I print the Date object with the same date format. If the input and the output for a date format are the same the date format is a candidate.

这篇关于从Java中日期字符串的未知格式返回日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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