simpledateformat

How to change Date format type between dates?

人走茶凉 提交于 2020-01-06 20:05:20
问题 how to change this date type "Thu Feb 02 12:00:00 GMT-12:00 2012" to another date type "yyyy-mm-dd HH:mm:ss"? If "Thu Feb 02 12:00:00 GMT-12:00 2012" is the String type, how to convert Date type of "yyyy-MM-dd HH:mm:ss"? java code: DateFormat inputDF = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy"); DateFormat outputDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date dd = inputDF.parse("Thu Feb 02 12:00:00 GMT-12:00 2012"); String strDate = outputDF.format(dd); The output is String

Java NumberFormatException in SimpleDateFormat.getDateInstance()

核能气质少年 提交于 2020-01-06 17:58:29
问题 I can't understand the reason of NumberFormatException in this code: SimpleDateFormat format = (SimpleDateFormat) SimpleDateFormat.getDateInstance(); Below is my LogCat output: 10-30 18:04:05.600: W/System.err(23899): java.lang.NumberFormatException: Invalid int: "" 10-30 18:04:05.600: W/System.err(23899): at java.lang.Integer.invalidInt(Integer.java:138) 10-30 18:04:05.600: W/System.err(23899): at java.lang.Integer.parseInt(Integer.java:359) 10-30 18:04:05.600: W/System.err(23899): at java

Java NumberFormatException in SimpleDateFormat.getDateInstance()

你说的曾经没有我的故事 提交于 2020-01-06 17:57:33
问题 I can't understand the reason of NumberFormatException in this code: SimpleDateFormat format = (SimpleDateFormat) SimpleDateFormat.getDateInstance(); Below is my LogCat output: 10-30 18:04:05.600: W/System.err(23899): java.lang.NumberFormatException: Invalid int: "" 10-30 18:04:05.600: W/System.err(23899): at java.lang.Integer.invalidInt(Integer.java:138) 10-30 18:04:05.600: W/System.err(23899): at java.lang.Integer.parseInt(Integer.java:359) 10-30 18:04:05.600: W/System.err(23899): at java

Java determine one dateformat from several dateformats

泪湿孤枕 提交于 2020-01-06 12:55:49
问题 We want to get a correct dateformat from LOG files generated by different systems with different language and log mechanism. We thought this can be done be a SimpleDataFormat.parse and try-catch exception way. But the follow code shows a problem. String tryparseString = "18-01-22 00:03:34:071"; try { SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(sdf1.parse(tryparseString)); System.out.println(sdf1.format(sdf1.parse(tryparseString))); System.out

17.java常用类

£可爱£侵袭症+ 提交于 2020-01-06 11:11:22
一、字符串相关类 1.String类   String:字符串,使用一对""引起来表示。1.String类是声明为final的,不可被继承2.String实现了Serializable接口:表示字符串是支持序列化的。 实现了Comparable接口:表示String可以比较大小3.String内部定义了final char[] value用于存储字符串数据4.String:代表不可变的字符序列。简称:不可变性。 体现:1.当对字符串重新赋值时,需要重写指定内存区域赋值,不能使用原有的value进行赋值。 2. 当对现有的字符串进行连接操作时,也需要重新指定内存区域赋值,不能使用原有的value进行赋值。 3. 当调用String的replace()方法修改指定字符或字符串时,也需要重新指定内存区域赋值,不能使用原有的value进行赋值。5.通过字面量的方式(区别于new)给一个字符串赋值,此时的字符串值声明在字符串常量池中。6.字符串常量池中是不会存储相同内容的字符串的。 (一)String的实例化方式:方式一:通过字面量定义的方式。通过字面量定义的方式:此时的s1和s2的数据javaEE声明在方法区中的字符串常量池中。 方式二:通过new + 构造器的方式。通过new + 构造器的方式:此时的s3和s4保存的地址值,是数据在堆空间中开辟空间以后对应的地址值。 面试题:String

Parse a empty string into SimpleDateFormat

 ̄綄美尐妖づ 提交于 2020-01-06 09:54:57
问题 So, so far I have this: static SimpleDateFormat df = new SimpleDateFormat("dd MM yyyy"); jDateChooser8 = new com.toedter.calendar.JDateChooser(); when I parse the right date let's say this one: jDateChooser8.setDate(df.parse("24 07 1987")); it's ok, but when I try to parse "" (empty string) jDateChooser8.setDate(df.parse("")); I get an exeption: first line of error is: java.text.ParseException: Unparseable date: "" all I want to do is set date to "" , how to do it? 回答1: The javadoc for parse

Parse a empty string into SimpleDateFormat

蹲街弑〆低调 提交于 2020-01-06 09:54:34
问题 So, so far I have this: static SimpleDateFormat df = new SimpleDateFormat("dd MM yyyy"); jDateChooser8 = new com.toedter.calendar.JDateChooser(); when I parse the right date let's say this one: jDateChooser8.setDate(df.parse("24 07 1987")); it's ok, but when I try to parse "" (empty string) jDateChooser8.setDate(df.parse("")); I get an exeption: first line of error is: java.text.ParseException: Unparseable date: "" all I want to do is set date to "" , how to do it? 回答1: The javadoc for parse

Parsing string to date with timezone in national format

南笙酒味 提交于 2020-01-06 03:05:54
问题 I try to parse string (russian locale) "01 августа 2014, пятница. 20:00 МСК" to java.util.Date. I try this code: String dateString = "01 августа 2014, пятница. 20:00 МСК" Locale rusLocale = new Locale.Builder().setLanguage("ru").setScript("Cyrl").build(); String pattern = "dd MMMM yyyy, EEEE. HH:mm z" Date date = SimpleDateFormat(pattern, rusLocale).parse(dateString) With month and weekday this code work fine, but when I try to parse string with timezone name МСК I get java.text

How to make JDatePicker text field formatted for input?

∥☆過路亽.° 提交于 2020-01-04 09:38:28
问题 org.jdatepicker is used In my app input field should be editable, so I added datePicker = new JDatePickerImpl(datePanel, new DateLabelFormatter()); datePicker.setTextEditable(true); But now I can write any bs to it: screenshot. I need to add something like mf = new MaskFormatter("##.##.####"); mf .setPlaceholderCharacter('.'); to limit input to mask. But how to do this? JDatePickerImpl isn't a JFormattedTextField. When I choose date from calendar it's formatted right way. My

ThreadLocal SimpleDateFormat in an Enum?

≯℡__Kan透↙ 提交于 2020-01-04 06:08:58
问题 I am doing some refactoring of our date formatting code because we've managed to introduce numerous inconsistencies for various reasons. I understand that it's best to have a ThreadLocal SimpleDateFormat . After discussing here we are unsure if ThreadLocal is even required when using in an Enum because we never change the instance and don't expose it so it can't be mutated? if it is still required does being an Enum, like this, break anything? Is anything else broken or not doing what I think