gpt4 book ai didi

java.lang.IllegalArgumentException : Illegal pattern character 'Y' for SimpleDateFormat

转载 作者:IT老高 更新时间:2023-10-28 20:44:52 29 4
gpt4 key购买 nike

以下代码:

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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com