datetime-parsing

Python parsing date with strptime

◇◆丶佛笑我妖孽 提交于 2019-12-02 00:48:41
问题 I have url that returns date in this format url_date = "2015-01-12T08:43:02Z" I don't know why there are strings, it would have been simpler to get it as "2015-01-1208:43:02" which would have been simpler to parse using datetime.datetime.strptime(url_date , '%Y-%m-%d') but it does not work. I have tried with %Y-%m-%d %Y-%m-%d-%H-%M-%S %Y-%m-%d-%H-%M-%S-%Z But I keep getting errors like "time data 2015-01-12T08:43:02Z does not match ..." 回答1: The format you are looking for is - '%Y-%m-%dT%H:%M

How to Pick Timezone from ISO 8601 format String into a Calendar instace

那年仲夏 提交于 2019-12-01 23:26:25
问题 As an input I have a string which is a String in ISO 8601 to represent date. For example: "2017-04-04T09:00:00-08:00" The last part of String , which is "-08:00" denotes TimeZone Offset. I convert this string into a Calendar instance as shown below: Calendar calendar = GregorianCalendar.getInstance(); Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).parse(iso8601Date); calendar.setTime(date); iso8601Date is "2017-04-04T09:00:00-08:00" But this does not pick timezone and

How to Pick Timezone from ISO 8601 format String into a Calendar instace

与世无争的帅哥 提交于 2019-12-01 22:09:48
As an input I have a string which is a String in ISO 8601 to represent date. For example: "2017-04-04T09:00:00-08:00" The last part of String , which is "-08:00" denotes TimeZone Offset. I convert this string into a Calendar instance as shown below: Calendar calendar = GregorianCalendar.getInstance(); Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).parse(iso8601Date); calendar.setTime(date); iso8601Date is "2017-04-04T09:00:00-08:00" But this does not pick timezone and if I get timezone from Calendar instance, it gives currently set instance of the laptop and does not

Python parsing date with strptime

♀尐吖头ヾ 提交于 2019-12-01 22:06:50
I have url that returns date in this format url_date = "2015-01-12T08:43:02Z" I don't know why there are strings, it would have been simpler to get it as "2015-01-1208:43:02" which would have been simpler to parse using datetime.datetime.strptime(url_date , '%Y-%m-%d') but it does not work. I have tried with %Y-%m-%d %Y-%m-%d-%H-%M-%S %Y-%m-%d-%H-%M-%S-%Z But I keep getting errors like "time data 2015-01-12T08:43:02Z does not match ..." The format you are looking for is - '%Y-%m-%dT%H:%M:%SZ' . Example - >>> url_date = "2015-01-12T08:43:02Z" >>> import datetime >>> datetime.datetime.strptime

How to convert timestamp string to epoch time?

南楼画角 提交于 2019-12-01 21:04:11
I have time stamp in format 2017-18-08 11:45:30.345 . I want to convert it to epoch time, so I am doing below: String timeDateStr = "2017-18-08 11:45:30.345"; DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-dd-MM HH:mm:ss.SSS"); ZonedDateTime zdt = ZonedDateTime.parse(timeDateStr, dtf); System.out.println(zdt.toInstant().toEpochMilli()); I am getting below error: java.time.format.DateTimeParseException: Text '2017-18-08 11:45:30.345' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor I also tried different formats but still getting errors. Note : originally the

How to convert timestamp string to epoch time?

余生长醉 提交于 2019-12-01 20:30:56
问题 I have time stamp in format 2017-18-08 11:45:30.345 . I want to convert it to epoch time, so I am doing below: String timeDateStr = "2017-18-08 11:45:30.345"; DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-dd-MM HH:mm:ss.SSS"); ZonedDateTime zdt = ZonedDateTime.parse(timeDateStr, dtf); System.out.println(zdt.toInstant().toEpochMilli()); I am getting below error: java.time.format.DateTimeParseException: Text '2017-18-08 11:45:30.345' could not be parsed: Unable to obtain

TryParseExact returns false, though I don't know why

守給你的承諾、 提交于 2019-12-01 15:23:25
问题 Method TryParseExact in code block below returns true . I would like to know why. I think this date "2013.03.12" is invalid because this is not separated by slash but dot. After I changed the CultureInfo "de-De" to "en-US" , the method returns false . This could be a hint but I still don't know why this happens. var format = new string[] { "yyyy/MM/dd" }; var parsed = new DateTime(); var result = DateTime.TryParseExact("2013.03.12", format, new CultureInfo("de-DE"), DateTimeStyles.None, out

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

拟墨画扇 提交于 2019-12-01 09:27:35
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 = readDate.parse(rssDateTime); SimpleDateFormat writeDate = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z")

How to create DateTimeformatter with optional seconds arguments

若如初见. 提交于 2019-12-01 05:56:58
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 final String DATE_TIME_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss"; DateTimeFormatter formatter1 = new

Failed to parse single digit hour and lowercase am-pm of day into Java 8 LocalTime

故事扮演 提交于 2019-11-30 21:08:36
When I try to run the following code: LocalTime test = LocalTime.parse("8:00am", DateTimeFormatter.ofPattern("hh:mma")); I get this: Exception in thread "main" java.time.format.DateTimeParseException: Text '8:00am' could not be parsed at index 0 Any idea why this might be happening? The AM/PM tokens have* to be uppercase: LocalTime test = LocalTime.parse("8:00AM", DateTimeFormatter.ofPattern("hh:mma")); Patterns definitions for hours: Symbol Meaning Presentation Examples ------ ------------ ------------ -------- a am-pm-of-day text PM h clock-hour-of-am-pm (1-12) number 12 K hour-of-am-pm (0