datetime-parsing

Getting wrong date when I am trying to parse actual date

主宰稳场 提交于 2020-01-07 04:22:28
问题 My actual date format is: Saturday, June 10 11:18 AM I want to convert this format to yyyy-MM-dd HH:mm:ss . For that I am trying to parse input string using below code: SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM dd HH:mm aa", Locale.ENGLISH); Log.d("date:","date is:"+format.parse(resultstr)); The output of the line gives: Wed Jun 10 00:00:00 GMT+05:30 1970 But I don't know why it is giving this value instead of actual value. 回答1: java.time.MonthDay You might be able to parse

Time parsing issue on Android

别等时光非礼了梦想. 提交于 2019-12-30 10:26:05
问题 I am getting a parse exception when trying to parse the time string 02:22 p.m. . I have the following conversion function: public static long convertdatetotimestamp(String datestring, String newdateformat, String olddateformat){ SimpleDateFormat originalFormat = new SimpleDateFormat(olddateformat,Locale.ROOT); SimpleDateFormat targetFormat = new SimpleDateFormat(newdateformat,Locale.ROOT); Date date = null; try { date = originalFormat.parse(datestring); String formattedDate = targetFormat

new SimpleDateFormat(“hh:mm a”, Locale.getDefault()).parse(“04:30 PM”) giving Unparseable exception

↘锁芯ラ 提交于 2019-12-25 03:19:09
问题 Strange things happen at most desperate times. I'm experiencing a bit strange thing in this line of code Date time = new SimpleDateFormat("hh:mm a", Locale.getDefault()).parse("04:30 PM"); is giving "Unparseable date: \"04:30 PM\" (at offset 6)" exception in Android 6.0 and Android 6.0.1 devices only, in production app (on Google Play Store). PS: I'm unable to regenerate this bug on Android 6.0 Emulator & HTC Desire 10 Pro Android 6.0.1. Any help to regenerate this bug locally or how to way

DateTimeFormatter create pattern [duplicate]

依然范特西╮ 提交于 2019-12-25 01:23:21
问题 This question already has answers here : How to get start and end range from list of timestamps? (2 answers) Converting ISO 8601-compliant String to java.util.Date (28 answers) Closed 6 months ago . I have this date: 2008-01-10T11:00:00-05:00 (date, T(separator), time, offset) I have this: DateTimeFormatter.ofPattern("yyyy-MM-ddSEPARATORHH-mm-ssOFFSET") I use this table to create my pattern. But, I don't find how to note SEPARATOR (T) and OFFSET. For OFFSET exists this: x zone-offset offset-x

Conversion of a date to epoch Java [duplicate]

余生长醉 提交于 2019-12-23 07:08:07
问题 This question already has answers here : SimpleDateFormat producing wrong date time when parsing “YYYY-MM-dd HH:mm” (4 answers) Closed last year . I want to convert 2018-02-21 15:47:35 UTC to epoch UTC form. How do we do it? I am currently in PST. SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-DD HH:MM:SS"); df.setTimeZone(TimeZone.getTimeZone("UTC")); date = df.parse(dateString).getTime(); The code above should return the number of milliseconds since January 1, 1970, 00:00:00 GMT , but

Conversion of a date to epoch Java [duplicate]

陌路散爱 提交于 2019-12-23 07:07:20
问题 This question already has answers here : SimpleDateFormat producing wrong date time when parsing “YYYY-MM-dd HH:mm” (4 answers) Closed last year . I want to convert 2018-02-21 15:47:35 UTC to epoch UTC form. How do we do it? I am currently in PST. SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-DD HH:MM:SS"); df.setTimeZone(TimeZone.getTimeZone("UTC")); date = df.parse(dateString).getTime(); The code above should return the number of milliseconds since January 1, 1970, 00:00:00 GMT , but

Jackson: parse custom offset date time

不问归期 提交于 2019-12-20 10:47:31
问题 I have a model which has a timestamp property: class Model { @JsonProperty("timestamp") private OffsetDateTime timestamp; } The format of the timestamp is as following: 2017-09-17 13:45:42.710576+02 OffsetDateTime is unable to parse this: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.time.OffsetDateTime from String "2017-09-17 13:45:42.710576+02": Text '2017-09-17 13:45:42.710576+02' could not be parsed at index 10 How can I fix this? 回答1:

DateTimeParseException: Text '2019-06-07 12:18:16' could not be parsed

試著忘記壹切 提交于 2019-12-20 07:47:06
问题 I have following code to convert an Instant to String then convert it back to I String timestampString = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")); LOGGER.info("timestampString: " + timestampString); Instant instant = LocalDateTime.parse(timestampString, DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")).toInstant(ZoneOffset.UTC); it print the timestampString as: 2019-06-07 12:45:57 and failed at parse the string: java.time.format.DateTimeParseException:

Android converting date time parse error (even tried joda time)

对着背影说爱祢 提交于 2019-12-19 09:26:23
问题 I'm parsing a number of news feeds and each item's pubDate follows the same format: Sun, 11 Jun 2017 18:18:23 +0000 Unfortunately one feed does not: Sat, 10 Jun 2017 12:49:45 EST I have tried to parse the date with no luck using androids java date and SimpleDateFormat : try { Calendar cal = Calendar.getInstance(); TimeZone tz = cal.getTimeZone(); SimpleDateFormat readDate = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); readDate.setTimeZone(TimeZone.getTimeZone("UTC")); Date date =

How to create DateTimeformatter with optional seconds arguments

可紊 提交于 2019-12-19 06:57:52
问题 I am trying to create a DateTimeformatter to validate following date times: String date1 = "2017-07-06T17:25:28"; String date2 = "2017-07-06T17:25:28.1"; String date3 = "2017-07-06T17:25:28.12"; String date4 = "2017-07-06T17:25:28.123"; String date5 = "2017-07-06T17:25:28.1234"; String date6 = "2017-07-06T17:25:28.12345"; String date7 = "2017-07-06T17:25:28.123456"; String date8 = "2017-07-06T17:25:28."; I have tried the following date time formatter to validate above dates: public static