date-parsing

convert String “yyyy-MM-dd” to LocalDateTime

廉价感情. 提交于 2019-12-21 03:34:15
问题 Is there any way to convert a date String to LocalDateTime where the format "yyyy-MM-dd" ? If I try this: DateTimeFormatter DATEFORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDateTime ldt = LocalDateTime.parse(string, DATEFORMATTER); I got this exception: java.time.format.DateTimeParseException: Text '2017-03-13' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2017-03-13 of type java.time.format.Parsed at java.time.format

Parsing with Java 8 DateTimeFormatter and Spanish month names

时光毁灭记忆、已成空白 提交于 2019-12-19 09:03:57
问题 With the 'old', pre-Java 8 SimpleDateFormat I can do: new java.text.SimpleDateFormat("MMM yyyy", new java.util.Locale("es", "ES")).parse("Mayo 2017") to get the Date object of a date with Spanish month names. How can I achieve the same with Java 8 and DateTimeFormatter ? I tried: DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).withLocale(new Locale("es", "ES")).ofPattern("MMM yyyy").parse("Mayo 2017") but only get a java.time.format.DateTimeParseException . 回答1: The call to

Automatic Date/Time parser without specifying format

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 07:36:10
问题 I am searching for a java library that can parse a string into a POJO without specifying the format. I have researched POjava. Is there anyother library which does similar thing? DateTime dateTime = DateTimeParser.parse("21/02/13"); //If unclear use the cultural information passed DateTime dateTime = DateTimeParser.parse("01/02/13", new Locale("en-us")); //Should also work with time zones DateTime dateTime = DateTimeParser.parse("2011/12/13T14:15:16+01:00"); I found the following links with

Inconsistent date parsing using SimpleDateFormat

此生再无相见时 提交于 2019-12-18 04:43:11
问题 I'm really scratching my head on this one. I've been using SimpleDateFormat s with no troubles for a while, but now, using a SimpleDateFormat to parse dates is (only sometimes) just plain wrong. Specifically: SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date date = sdf.parse("2009-08-19 12:00:00"); System.out.print(date.toString()); prints the string Wed Aug 19 00:00:00 EDT 2009 . What the heck? - it doesn't even parse into the wrong date all the time! Update: That

Parsing a String into Date with DateFormat not parsing correctly

六月ゝ 毕业季﹏ 提交于 2019-12-17 21:15:41
问题 I've been searching all over and just can't find a explanation or reason why this is happening but the parse(String) method of DateFormat just isn't parsing my String correctly. I'm trying to parse a String into the date format that is used for HTTP headers and got as far as getting the String on its own such as: Thu, 11 Nov 2010 18:34:22 GMT Which is in the format: E, d MMM yyyy HH:mm:ss z But when I use df.parse(dateStr); this is what I get out of it: Thu Nov 11 18:34:22 GMT 2010 Which is

Fastest way to parse a YYYYMMdd date in Java [closed]

蓝咒 提交于 2019-12-17 18:57:50
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . When parsing a YYYYMMdd date, e.g. 20120405 for 5th April 2012, what is the fastest method? int year = Integer.parseInt(dateString.substring(0, 4)); int month = Integer.parseInt(dateString.substring(4, 6)); int

How to use JSON.parse reviver parameter to parse date string

試著忘記壹切 提交于 2019-12-17 18:30:43
问题 My JSON string contains a date field that returns such a value: "2009-04-04T22:55:16.0000000-04:00" I am particularly interested in parsing only the date compartment not the time. I tried using a reviver function, but interestingly the reviver function is never invoked! (tried on Firefox) Here is my code to accomplish that: var Site = { ..... dateReviver: function(key, value) { var a; if (typeof value === 'string') { a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec

Problem with date formats in JavaScript with different browsers

↘锁芯ラ 提交于 2019-12-17 05:07:08
问题 I am working with dates in an RSS feed, but am finding differing results when using the code below in IE, Chrome and Firefox: new Date('2001-01-01T12:00:00Z') Firefox is happy with that, but Chrome and IE return Invalid Date. I thought I'd try replacing the T and Z as follows: new Date('2001-01-01 12:00:00') This time Chrome is happy with that, but Firefox and IE return Invalid Date. Any ideas what I should do to get a date object in all browsers with this format?! Many thanks, Tim 回答1: This

Use variable in re.sub, for Python parsing multiple datetime-format strings?

本小妞迷上赌 提交于 2019-12-13 15:22:56
问题 I'm trying to come up with a function to translate various human date/time-format strings to Python compatible ones (from '*yyyy-MMM-dd*' to '*%Y-%b-%d*' ). So far I built the translate dictionary below (a list of tuples [('yyyy','%Y'),('MMM','%b'),...] ) so I can convert placeholder fields in input format-strings into strptime '%x' fields e.g.: 'yyyy-MMM-dd' --> '{5}-{3}-{12}' But what do I do next? I've tried multiple ways: >>> re.sub('({\d+})',translateList['\1'][1],'{5}-{3}-{12}')

Date parsed with gmt + 2 hours

风流意气都作罢 提交于 2019-12-13 09:11:54
问题 I always get the wrong date when I use var date = new Date(timestring) , there is always +2 GMT hours. var unsortedPlayTimes = [{date:'2014-08-11T09:30:00'}, {date:'2014-08-11T08:30:00'}, {date:'2014-08-11T08:15:00'}, {date:'2014-08-11T08:45:00'}, {date:'2014-08-11T12:30:00'}, {date:'2014-08-11T10:30:00'}, {date:'2014-08-11T11:30:00'}, {date:'2014-08-11T07:30:00'}, {date:'2014-08-11T13:00:00'}, {date:'2014-08-11T23:00:00'}, {date:'2014-08-12T00:00:00'}, {date:'2014-08-12T01:00:00'}, {date: