simpledateformat

SimpleDateFormat parse returns wrong value

最后都变了- 提交于 2019-12-11 02:47:59
问题 I have this code: public static String formatMinSecOrHourMinSec(final String length) { try { final SimpleDateFormat hhmmss = new SimpleDateFormat("HH:mm:ss", Locale.GERMAN); final Date date = hhmmss.parse(length); final GregorianCalendar gc0 = new GregorianCalendar(Locale.GERMAN); gc0.setTime(date); if(gc0.getTimeInMillis() >= 3600 * 1000){ return hhmmss.format(gc0.getTime()); }else{ final SimpleDateFormat mmss = new SimpleDateFormat("mm:ss"); return mmss.format(gc0.getTime()); } } catch

Java date - 12am is stored as 24?

…衆ロ難τιáo~ 提交于 2019-12-11 01:52:58
问题 So me and my partner have been working on this project for a while now. We work with dates A LOT in this project, and we recently noticed an issue, and we are rather deep in at this point. We store our times in SQLlite (Android project) as a formatted string, since a lot of the time they are directly bound to listviews and such. The problem we noticed, which i found kind of odd, is that that SimpleDateTimeFormat object, when used to format to 24h time (its a medical based project, so 24h time

Getting the correct GMT format using DateFormat Object

六眼飞鱼酱① 提交于 2019-12-11 01:38:39
问题 If i have a File object how can i get the lastModified() date of this file in this GMT format: Mon, 23 Jun 2011 17:40:23 GMT . For example, when i call the java method lastModified() on a file and use a DateFormat object to getDateTimeInstance(DateFormat.Long, DateFormat.Long) and also set the TimeZone to GMT, the file date displays in different format: File fileE = new File("/Some/Path"); Date fileDate = new Date (fileE.lastModified()); DateFormat dateFormat = DateFormat.getDateTimeInstance

Deserializing date from ASP.NET, with Jackson

久未见 提交于 2019-12-11 01:29:32
问题 I have a date in a json string (returned from an ASP.NET rest service) that looks like this: "created": "/Date(1277931782420-0700)/" Jackson is not able to parse this date. I can write my own date format and pass it in to mapper.getDeserializationConfig().setDateFormat(); but i was wondering if there is an easier/better way to do this... 回答1: I think defining date format is a reasonable way to do it. Alternatively you could define your own JsonDeserializer, register it, but it's not any

Why don't I get the year right using SimpleDateFormat in java?

丶灬走出姿态 提交于 2019-12-11 01:07:00
问题 I trying to parse a data in a MySql Format, I ran across SimpleDateFormat . I can get the proper day and month, but I got a strange result for the year : date = 2009-06-22; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date d = sdf.parse(date); System.println(date); System.println(d.getDate()); System.println(d.getMonth()); System.println(d.getYear()); Outputs : 2009-06-22 22 OK 5 Hum... Ok, months go from 0 to 11 109 o_O WTF ? I tried changing the format to YYYY-MM-dd (got an

Android /java Time Format?

喜夏-厌秋 提交于 2019-12-11 00:54:21
问题 I have time as a "2011-12-03 12:00:19" how to convert it in "Fri 2 December 2011 " ,I know this http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html ,But gives me Error: Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date at java.text.DateFormat.format(Unknown Source) at java.text.Format.format(Unknown Source) at com.timestamp.NewTimeStamp.<init>(NewTimeStamp.java:21) at com.timestamp.NewTimeStamp.main(NewTimeStamp.java:35)

Java - How to convert this string to date?

江枫思渺然 提交于 2019-12-10 22:33:01
问题 I am receiving this from the server and I don´t understand what the T and Z means, 2012-08-24T09:59:59Z What's the correct SimpleDateFormat pattern to convert this string to a Date object? 回答1: This is ISO 8601 Standard. You may use SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); to convert this. 回答2: This is the ISO datetime format, see here, T is the time separator and Z is the zone designator for the zero UTC offset. There is a very similar, if not identical

Date with SimpleDateFormat in Java

谁说我不能喝 提交于 2019-12-10 21:38:17
问题 The following code attempts to parse a date 31-Feb-2013 13:02:23 with a given format. DateFormat dateFormat=new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss"); System.out.println(dateFormat.parse("31-Feb-2013 13:02:23")); It returns Sun Mar 03 13:02:23 IST 2013 . I need to invalidate such dates indicating invalid date . This (and so forth) date shouldn't be parsed (or should be invalidated in any other way). Is this possible? 回答1: Use DateFormat.setLenient(boolean) method with false argument:

Why are different long values converted into the same date/time?

放肆的年华 提交于 2019-12-10 21:12:40
问题 public static void getTime() { SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); Time t1 = new Time(Long.parseLong("1369213412435")); Time t2 = new Time(Long.parseLong("1369213412245")); System.out.println(sdf.format(t1)); System.out.println(sdf.format(t2)); } Why does the above code prints, 2013-05-22 17:03:32 2013-05-22 17:03:32 回答1: The two dates differ only by milliseconds (435 or 245), which you ignore in your format. Use: SimpleDateFormat sdf = new SimpleDateFormat(

Java, converting Date to String and back produced wrong Date

为君一笑 提交于 2019-12-10 20:37:30
问题 I am trying to convert a Date to String and then back again to Date . However I found out that the final date is different from the original date, what gives? //1975-06-20 Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 1975); cal.set(Calendar.MONTH, 5); cal.set(Calendar.DAY_OF_MONTH, 20); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); System.out.println(cal); Date originalDate = cal.getTime(); System.out.println("Date 1: " + originalDate