本文介绍了解析美国的日期到yyyy-MM-dd,java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解析我认为等于美国短日期的日期3/27/11。

I want to parse the date "3/27/11" which I think is equal to US short date.

DateFormat df1 = new SimpleDateFormat("MM/dd/yy");
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
Date date = (Date) df1.parseObject("03/27/11");
System.out.println("New date: " + df2.format(date));

我在几个java教程中发现了上面的代码,但似乎不起作用。
对于某些我如何得到,

I found the code above in several java tutorials but it doesn't seem to work.For some how I get,

Exception in thread "main" java.lang.AssertionError: Default directory must be absolute/non-UNC

这是我想要实现的,

输入:3/27/11

(03/27/11也应该是有效的输入)

输出:2011-03-27

input: 3/27/11
(03/27/11 should also be a valid input)
output: 2011-03-27

提前感谢

推荐答案

当我运行它打印



When I run this it prints

New date: 2011-03-27

我怀疑您的问题与此无关,而是您的应用程序的默认目录是UNC路径。即您的错误消息说明。

I suspect your problem is nothing to do with this but rather you have a default directory for your application which is a UNC path. i.e. exactly what your error message says.

尝试从C:驱动器或使用网络驱动器盘符的路径运行此程序。

Try running this program from your C: drive or a path using a network drive letter.

这篇关于解析美国的日期到yyyy-MM-dd,java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 17:46