日期Java SimpleDataFormat使用带有jolly字符的模式
有没有一种方法可以用包含一些“特殊字符”或“jolly字符”作为分隔符的模式来解析日期,并使用标准SimpleDataFormat?我想使用模式"yyyy MM dd"
、"yyyy/MM/dd"
、"yyyy-MM-dd"
等等来解析我的日期。。。,所以我在搜索类似“yyyy*MM*dd”的东西,其中*是一个特殊字符,意思是“随机字符”
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
Date d = fmt.parse(stringdate);
# 1 楼答案
你应该试试这个
# 2 楼答案
使用正则表达式过滤掉有趣的字符,然后解析过滤后的字符串
# 3 楼答案
您可以尝试将输入“标准化”为所需格式: