- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
以下代码:
Calendar now = Calendar.getInstance();
month = now.get(Calendar.MONTH) + 1;
year = now.get(Calendar.YEAR);
System.out.println("Month " + month + " year " + year);
SimpleDateFormat dt1 = new SimpleDateFormat("MMMM YYYY");
e.setMonthnYear(dt1.format(now.getTime()));
在服务器上部署后显示以下异常:
java.lang.IllegalArgumentException: Illegal pattern character 'Y'
java.text.SimpleDateFormat.compile(SimpleDateFormat.java:768)
java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:575)
java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:500)
java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:475)
iland.employee.EmployeeAction.fetchAllAtted(EmployeeAction.java:169)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
在我的本地主机上,我使用的是 JDK v1.8
,上面的代码运行良好,但在服务器上却无法运行。
我该如何解决这个问题?
最佳答案
试试
SimpleDateFormat dt1 = new SimpleDateFormat("MMMM yyyy");
关于java.lang.IllegalArgumentException : Illegal pattern character 'Y' for SimpleDateFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25337241/
我们在 java.util.Date 对象的 JAXB 序列化/反序列化过程中使用 SimpleDateFormat,我正在编写以下实用程序来实现这一点 public DateFormat getDa
我正在尝试借助 SimpleDateFormat 将时区设置为不同国家/地区的时区。 SimpleDateFormat.format() 返回给定时区的正确当前时间,但 SimpleDateForma
我正在尝试将 DatePicker 日期格式化为 SimpleDateFormat(“yyyy-MM-dd HH:mm:ss Z”)。有人告诉我,我需要使用 SimpleDateFormatter 将
我遇到this article并感到困惑 在我们的项目中,有几个地方我们使用 ThreadLocal 来构造 ThreadLocal 变量 在其他一些地方,我们在私有(private)本地方法中构造了
在创建 Date 对象期间,我遇到了一个奇怪的问题。我有以下代码将日期的时区设置为 UTC。在解析语句之前,我看到 sdfDate 的时区为 UTC,但在解析语句之后,我看到 PunchDate 具有
我的日期格式如下:2010-03-01T00:00:00-08:00 我已经抛出了以下 SimpleDateFormats 来解析它: private static final SimpleDateF
我有一个从给定日期中提取确切时间的逻辑(例如: 12:00 PM )。 在逻辑的最后,我使用了 SimpleDateFormat解析日期。 当我在 Android 设备上运行代码时,一切正常。 此外,
根据下图,当我使用 item.takendate至SimpleDateFormat 我得到了 《2016年1月》而不是 《2017年1月》 这里发生了什么?请指教。 编辑 但是,当我使用 cdate
我正在尝试使用 java.text.SimpleDateFormat 将日期字符串解析为 java.util.Date;但是,生成的格式化日期是错误的。 这是一个显示问题的测试用例: @Test pu
我正在尝试将“5 月 15 日星期一下午 1 点”格式的字符串解析为日期时间,以便我可以将其输入到数据库中。但是,当我对此进行测试时,解析并没有在正确的日子返回。有谁知道发生了什么? import j
背景: 在我的数据库表中,我有两个时间戳 timeStamp1 = 2011-08-23 14:57:26.662 timeStamp2 = 2011-08-23 14:57:26.9 当我执行“OR
我需要解析以下来自网络服务的日期。 2014-09-16T18:05:00.000-05:00 所以我尝试创建 SimpleDateFormat 对象 SimpleDateFormat simpleD
我很困惑为什么 SimpleDateFormat 没有正确解析以下输入数据。 我试图在 String 上测试各种可能允许的日期格式,看看它是否可以使用其中一种格式正确解析。 注意:我使用的其他不正确的
我想将字符串存储到具有当前时间和日期的 Android 应用程序的数据库(SQLite)中。为此,我正在使用 SimpleDateFormat。不幸的是,它没有显示正确的时间。我尝试了两种选择。 第一
也许这个问题很傻,但我没有找到令我满意的答案。 我有一个 SimpleDataFormat,例如: sdf = new SimpleDateFormat("dd/MM/yyyy"); 如果我尝试解析这
这里我尝试比较 3 个日期,为此,我已将一个日期和两个字符串传递给函数。我使用简单的日期格式来制作 3 个相同格式的日期,以便我可以比较它们。但是对于两个字符串值,我在解析它时得到了错误的日期。有人可
我正在尝试将日期从 2009 年 5 月 15 日 19:24:11 PM MDT 转换为 20090515192411。但是当我尝试下面的代码时,读取格式本身将输入视为 5 月 16 日而不是 5
这个问题已经有答案了: How to get date from date time in java (6 个回答) Why can't this SimpleDateFormat parse thi
这个问题已经有答案了: Changing Java Timestamp format causes a change of the timestamp (2 个回答) Java / convert I
以下代码: SimpleDateFormat sdf = new SimpleDateFormat("MM/dd"); System.out.println(sdf.format(new Date(1
我是一名优秀的程序员,十分优秀!