datetime-parsing

Convert date into AEST using java

佐手、 提交于 2019-11-26 18:40:53
问题 I want to convert below date into AEST format using Java. 2018-01-08T02:10:24.000+0000w Below is the code which i am using for to convert . DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSzzz"); ZonedDateTime zdt = ZonedDateTime.parse( map.get("records-LastModifiedDate").toSt‌​ring().trim()); System.out.println(zdt); There is something wrong with the pattern? Please suggest. 回答1: You have to use the formatter when parsing the date string. Also you need to tell it

Java 8 Date and Time: parse ISO 8601 string without colon in offset [duplicate]

拜拜、爱过 提交于 2019-11-26 16:40:38
This question already has an answer here: Cannot parse String in ISO 8601 format, lacking colon in offset, to Java 8 Date 1 answer We try to parse the following ISO 8601 DateTime String with timezone offset: final String input = "2022-03-17T23:00:00.000+0000"; OffsetDateTime.parse(input); LocalDateTime.parse(input, DateTimeFormatter.ISO_OFFSET_DATE_TIME); Both approaches fail (which makes sense as OffsetDateTime also use the DateTimeFormatter.ISO_OFFSET_DATE_TIME ) because of the colon in the timezone offset. java.time.format.DateTimeParseException: Text '2022-03-17T23:00:00.000+0000' could

How can I parse a time string containing milliseconds in it with python?

≯℡__Kan透↙ 提交于 2019-11-26 11:42:51
I am able to parse strings containing date/time with time.strptime >>> import time >>> time.strptime('30/03/09 16:31:32', '%d/%m/%y %H:%M:%S') (2009, 3, 30, 16, 31, 32, 0, 89, -1) How can I parse a time string that contains milliseconds? >>> time.strptime('30/03/09 16:31:32.123', '%d/%m/%y %H:%M:%S') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.5/_strptime.py", line 333, in strptime data_string[found.end():]) ValueError: unconverted data remains: .123 DNS Python 2.6 added a new strftime/strptime macro %f , which does microseconds. Not sure if

Java: Date parsing, why do I get an error

£可爱£侵袭症+ 提交于 2019-11-26 11:39:47
问题 Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat(\"yyyy-MM-dd\'T\'HH:mm:ss.SZ\");//2018-02-05T18:00:51.001+0000 String text = dateFormat.format(date); Date test = dateFormat.parse(text); The first three lines work fine. When I try to parse the string into a date again I get an error. How can I solve this? The error looks like this: Caused by: java.text.ParseException: Unparseable date: \"2018-02-07T15:32:13.214+0100\" at java.text.DateFormat.parse(DateFormat.java:366) ~[na

How to parse a date string into a c++11 std::chrono time_point or similar?

偶尔善良 提交于 2019-11-26 09:28:20
问题 Consider a historic date string of format: Thu Jan 9 12:35:34 2014 I want to parse such a string into some kind of C++ date representation, then calculate the amount of time that has passed since then. From the resulting duration I need access to the numbers of seconds, minutes, hours and days. Can this be done with the new C++11 std::chrono namespace? If not, how should I go about this today? I\'m using g++-4.8.1 though presumably an answer should just target the C++11 spec. 回答1: std::tm tm

Parsing time string in Python

对着背影说爱祢 提交于 2019-11-26 06:36:46
问题 I have a date time string that I don\'t know how to parse it in Python. The string is like this: Tue May 08 15:14:45 +0800 2012 I tried datetime.strptime(\"Tue May 08 15:14:45 +0800 2012\",\"%a %b %d %H:%M:%S %z %Y\") but Python raises \'z\' is a bad directive in format \'%a %b %d %H:%M:%S %z %Y\' According to Python doc: %z UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive). What is the right format to parse this time string? 回答1: datetime.datetime.strptime has

Java 8 Date and Time: parse ISO 8601 string without colon in offset [duplicate]

梦想与她 提交于 2019-11-26 04:52:17
问题 This question already has an answer here : Cannot parse String in ISO 8601 format, lacking colon in offset, to Java 8 Date (1 answer) Closed last year . We try to parse the following ISO 8601 DateTime String with timezone offset: final String input = \"2022-03-17T23:00:00.000+0000\"; OffsetDateTime.parse(input); LocalDateTime.parse(input, DateTimeFormatter.ISO_OFFSET_DATE_TIME); Both approaches fail (which makes sense as OffsetDateTime also use the DateTimeFormatter.ISO_OFFSET_DATE_TIME )

SimpleDateFormat producing wrong date time when parsing “YYYY-MM-dd HH:mm”

人走茶凉 提交于 2019-11-26 04:51:43
问题 I am trying to parse a String ( YYYY-MM-dd HH:mm ) to Date , however getting wrong date than expected. CODE: 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.\"); } Produces: Sun Dec 30 08:30:00 EST 2012 (wrong) I tried setting Lenient off but no luck. Update

How can I parse a time string containing milliseconds in it with python?

柔情痞子 提交于 2019-11-26 03:34:07
问题 I am able to parse strings containing date/time with time.strptime >>> import time >>> time.strptime(\'30/03/09 16:31:32\', \'%d/%m/%y %H:%M:%S\') (2009, 3, 30, 16, 31, 32, 0, 89, -1) How can I parse a time string that contains milliseconds? >>> time.strptime(\'30/03/09 16:31:32.123\', \'%d/%m/%y %H:%M:%S\') Traceback (most recent call last): File \"<stdin>\", line 1, in <module> File \"/usr/lib/python2.5/_strptime.py\", line 333, in strptime data_string[found.end():]) ValueError: unconverted

Parsing ISO-8601 DateTime with offset with colon in Java

大兔子大兔子 提交于 2019-11-26 00:34:22
问题 I have a trouble with parsing date time in java, I have a strange date time format. How can I parse 2013-04-03T17:04:39.9430000+03:00 date time in java to format dd.MM.yyyy HH:mm in java? 回答1: The "strange" format in question is ISO-8601 - its very widely used. You can use SimpleDateFormat to reformat it in most way you please: SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); DateTime dtIn = inFormat.parse(dateString}); //where dateString is a date in ISO-8601