【java之Date类及SimpleDateFormat类】教程文章相关的互联网学习教程文章

java – 使用SimpleDateFormat.parse时出错【代码】

在我的程序中有一个非常奇怪的问题.在这里你可以看到String birthday和Log来检查它:birthday = String.valueOf(birthYear) + "-" + String.valueOf(birthMonth) + "-" + String.valueOf(birthDay); Log.i(TAG, "Birthday: " + birthday)然后我把它放到SimpleDateFormat并用Log检查它:SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");Date birthDate = sdf.parse(birthday); Log.i(TAG, "Birth date : " + birthDate...

java – Android SimpleDateFormat,如何使用它?【代码】

我试图像这样使用Android SimpleDateFormat:String _Date = "2010-09-29 08:45:22" SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");try {Date date = fmt.parse(_Date);return fmt.format(date); } catch(ParseException pe) {return "Date"; }结果很好,我有:2010-09-29 但是,如果我将SimpleDateFormat更改为SimpleDateFormat("dd-MM-yyyy");问题是我会得到03-03-0035 !!!! 为什么以及如何获得像dd-MM-yyyy这样...

Java:JFormattedTextField保存数字【代码】

在我的应用程序中,我想将数字(金额)输入到特定限制,因此使用了JFormattedTextField.限制为“12345678.99”,即“.”之前的8位数.和“.”之后的2.等等.这是我的实现代码,但它没有按预期结果.startBalTxt.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("########.##"))));startBalTxt.setText(resourceMap.getString("startBalTxt.text")); /...

java – DateFormat parse – 不以UTC格式返回日期【代码】

这里我的java代码尝试在Android设备上以UTC格式获取当前日期:public static Date getCurrentDateUTC() {try {TimeZone timeZoneUTC = TimeZone.getTimeZone("UTC");Date localTime = new Date();DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss Z");dateFormat.setTimeZone(timeZoneUTC);String dateUTCAsString = dateFormat.format(localTime);Debug.d(TAG, "getCurrentDateUTC: dateUTCAsString = " + d...

java – SimpleDateFormat类中可用的日期格式是什么?

任何人都可以告诉我SimpleDateFormat类中可用的日期格式. 我已经通过api但找不到满意的答案.非常感谢任何帮助.解决方法:日期和时间格式在下面有详细描述 SimpleDateFormat (Java Platform SE 7) – Date and Time Patterns 可能有n种格式你可以制作. ex – dd / MM / yyyy或YYYY-‘W’ww-u或者您可以混合和匹配字母以达到您所需的模式.图案字母如下. > G – 时代指示符(AD)>年 – 年(1996年; 96年)> Y – 周年(2009; 09)> M –...

java – 解析“YYYY-MM-dd HH:mm”时,SimpleDateFormat产生错误的日​​期时间【代码】

我试图将字符串(YYYY-MM-dd HH:mm)解析为日期,但是日期错误比预期错误. 码:Date newDate = null; String dateTime = "2013-03-18 08:30"; SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd HH:mm", Locale.ENGLISH); df.setLenient(false); try {newDate = df.parse(dateTime); } catch (ParseException e) {throw new InvalidInputException("Invalid date input."); }生产:Sun Dec 30 08:30:00 EST 2012 (wrong)我试过...

spring – JSP中的List中的${employee.id}抛出java.lang.NumberFormatException:对于输入字符串:“id”【代码】

我有一个JSP页面,在显示List< Employee>时工作正常.来自< c:forEach>中的以下方法.@RequestMapping(value = { "getAllEmployees", "/" }) public ModelAndView getAllEmployees() {// logger.info("Getting the all Employees.");List<Employee> employeeList = employeeService.getAllEmployees();return new ModelAndView("employeeList", "employeeList", employeeList); }而显示List< Employee>时,同一个JSP会抛出异常.从下面...

java.lang.numberformatexception:无效的double:“”【代码】

得到无效Double的错误java.lang.numberformatexception无效的双倍:“”这是什么原因 活动1package com.example.solarcalculator;import android.os.Bundle;import android.widget.Button;import android.annotation.SuppressLint;import android.app.Activity;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.EditText;import android.app.AlertDialog;impor...

java – simpledateformat使用’Z’文字解析日期[复制]【代码】

参见英文答案 > Converting ISO 8601-compliant String to java.util.Date 26个我试图解析一个看起来像这样的日期:2010-04-05T17:16:00Z这是每个http://www.ietf.org/rfc/rfc3339.txt的有效日期.“Z”字面意思“暗示UTC 是指定时间的首选参考点.“ 如果我尝试使用SimpleDateFormat和此模式解析它:yyyy-MM-dd'T'HH:mm:ss它将被解析为2010年4月5日17:16:00美国东部时间2010年 SimpleDateForm...

为什么Java的SimpleDateFormat不是线程安全的?

参见英文答案 > “Java DateFormat is not threadsafe” what does this leads to? 10个请告诉代码示例为什么SimpleDateFormat不是线程安全的.这堂课有什么问题?SimpleDateFormat的格式功能有问题吗?请给出一个在课堂上演示此错误的代码. FastDateFormat是线程安全的.为什么?b / w SimpleDateFormat和FastDateFormat有什么区别? 请用解释此问题的代码解释一下?解决方法:SimpleDateFormat将...

java – JFormattedTextField未正确清除【代码】

我正在做这个任务,制作一个解决数独的程序.我有一个带有SudokuTextBox网格的面板,扩展了JFormattedTextField.我有一个MaskFormatter,因此每个文本框只接受一个整数.然后在我的面板中,当密钥被释放时,我有这个代码.public void keyReleased(KeyEvent e) {SudokuTextBox tb = (SudokuTextBox) e.getSource();int row = tb.getRow();int col = tb.getCol();int value = toInteger(tb.getText());//System.out.println(value);if(sudok...

java – 什么是NumberFormatException以及如何解决?【代码】

参见英文答案 > What is a stack trace, and how can I use it to debug my application errors? 7个 Error Message: Exception in thread "main" java.lang.NumberFormatException: For input string: "Ace of Clubs"at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)at java.lang.Integer.parseInt(Integer.java:580)at java.lang.Integer.parseInt(Intege...

java – Groovy 2.5.0为methodcalltransformation提供了noclassdeffounderror【代码】

当我将我的项目从Groovy 2.4.*升级到Groovy 2.5.0时,它为org / codehaus / groovy / ast / methodcalltransformation提供了noclassdeffounderror使用Gradle进行编译时. 它在Groovy 2.4中运行良好. 在这里发布整个例外:org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileGroovy'.at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecut...

java的DateFormat、SimpleDateFormate类源码的详解

java的DateFormat、SimpleDateFormate类源码的详解 抽象类Format的定义public abstract class Format implements Serializable, Cloneable {private static final long serialVersionUID = -299282585814624189L;protected Format() {}public final String format (Object obj) {return format(obj, new StringBuffer(), new FieldPosition(0)).toString();}public abstract StringBuffer format(Object obj,StringBuffer toAppend...

java – 启用Guice的应用程序的Proguard优化(无混淆)后的ClassFormatError【代码】

我有一个启用Guice的应用程序工作正常,但当我使用Proguard优化它(即缩小大小)时,我收到以下错误消息(我用未捕获的异常处理程序捕获它):java.lang.ClassFormatError: LVTT entry for 'that' in class file com/google/inject/internal/util/$ImmutableList$RegularImmutableList does not match any LVT entry这可以防止应用程序正常运行.我不混淆代码. 有谁知道发生了什么?有解决方案/解决方法吗? 谢谢.解决方法:有时ProGuard会...