datetime-parsing

ParseException when parsing 3 character abbreviated month using SimpleDateFormat

半世苍凉 提交于 2019-11-28 14:16:25
问题 Here is my code, SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); Date dft = (Date) format.parse("16-MAY-2018 09:30:22:000"); I am getting below exception java.text.ParseException: Unparseable date: "16-MAY-2018 09:30:22" What's to be used to parse milliseconds? 回答1: The pattern should be MMM because there are three characters in the month. You should also prefer java.time classes to the ones you're currently using if you're on Java 8 or above: DateTimeFormatter

Datetime parsing error

只谈情不闲聊 提交于 2019-11-28 06:05:57
问题 I am having problem parsing dates in Java. Below is the code. String dateString = "2017-12-13T16:49:20.730555904Z"; List<String> formatStrings = Arrays.asList("yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'"); for (String formatString : formatStrings) { try { SimpleDateFormat formatter = new SimpleDateFormat(formatString); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); Date d = formatter.parse(dateString); System.out.println("Format is:" + formatString); System.out

How to unify date format using DateTimeFormatter

爷,独闯天下 提交于 2019-11-28 05:58:36
问题 I need to parse different time format into BASIC_ISO_DATE . Right now, there are 4 types of date format: 2016-10-01 (ISO_LOCAL_DATE) 2016T 201610T 2016-02-07T22:03:39.937Z (ISO 8601) Need to parse to 20161001 and print out, with default day is 01 , default month Jan . Examples: 2016T -> 20160101 201610T -> 20161001 How can I use DateTimeFormatter to achieve this? 回答1: Just to complement @Flown's answer (which works perfectly BTW), you can also use optional patterns (delimited by [] ):

Parse rfc3339 date strings in Python? [duplicate]

北城以北 提交于 2019-11-28 04:15:12
This question already has an answer here: How do I parse an ISO 8601-formatted date? 25 answers I have a datasets where all the dates have the following format: 2012-10-09T19:00:55Z I'd like to be able to be able to use methods like .weekday on them. How do I convert them to the proper format in Python? You can use dateutil.parser.parse to parse strings into datetime objects. dateutil.parser.parse will attempt to guess the format of your string, if you know the exact format in advance then you can use datetime.strptime which you supply a format string to (see Brent Washburne's answer). from

Convert date into AEST using java

空扰寡人 提交于 2019-11-28 02:29:36
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. You have to use the formatter when parsing the date string. Also you need to tell it to change the zone or zone offset to get it into AEST/AEDT. This might work: DateTimeFormatter dtf =

Natural/Relative days in Python

梦想与她 提交于 2019-11-27 07:25:09
I'd like a way to show natural times for dated items in Python. Similar to how Twitter will show a message from "a moment ago", "a few minutes ago", "two hours ago", "three days ago", etc. Django 1.0 has a "humanize" method in django.contrib. I'm not using the Django framework, and even if I were, it's more limited than what I'd like. Please let me (and generations of future searchers) know if there is a good working solution already. Since this is a common enough task, I imagine there must be something. While not useful to you at this very moment, it may be so for future searchers: The babel

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

邮差的信 提交于 2019-11-27 00:56:25
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. Simple std::tm tm = {}; std::stringstream ss("Jan 9 2014 12:35:34"); ss >> std::get_time(&tm, "%b %d %Y %H:%M:%S"); auto

Parse rfc3339 date strings in Python? [duplicate]

风格不统一 提交于 2019-11-27 00:20:51
问题 This question already has answers here : How do I parse an ISO 8601-formatted date? (26 answers) Closed 4 years ago . I have a datasets where all the dates have the following format: 2012-10-09T19:00:55Z I'd like to be able to be able to use methods like .weekday on them. How do I convert them to the proper format in Python? 回答1: You can use dateutil.parser.parse to parse strings into datetime objects. dateutil.parser.parse will attempt to guess the format of your string, if you know the

How to parse “yyyy-MM-dd'T'HH:mm:ss.SSSXXX” date format to simple in Android? [duplicate]

怎甘沉沦 提交于 2019-11-26 22:27:47
问题 This question already has answers here : Converting ISO 8601-compliant String to java.util.Date (28 answers) Closed last year . How do I can parse this date 2018-01-09T11:11:02.0+03:00 to dd.MM.yyyy hh:mm format in Android? And what does T between 09 and 11 mean? Thanks. I don't know how the back-end developer got this format. I am using Java. 回答1: If you are using java, you can use SimpeDateFormat with patterns: String date = "2018-01-09T11:11:02.0+03:00"; SimpleDateFormat dateformat = new

Parsing time string in Python

送分小仙女□ 提交于 2019-11-26 20:15:49
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? datetime.datetime.strptime has problems with timezone parsing. Have a look at the dateutil package : >>> from dateutil import parser >>> parser.parse