datetime-parsing

Problem with parse a LocalDateTime using java 8

岁酱吖の 提交于 2020-07-22 08:53:46
问题 I have this code, it's a simple string that I want to parse it to a LocalDateTime import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; public class DateClass { /** * @param args the command line arguments */ public static void main(String[] args) { String dateRaw = "2019-05-03 7:05:03"; DateTimeFormatter dtf = new DateTimeFormatterBuilder().appendPattern("uuuu-mm-dd HH:mm:ss").toFormatter(); LocalDateTime date=

How to convert UTC Date String and remove the T and Z in Java?

余生颓废 提交于 2020-06-11 06:08:48
问题 Am using Java 1.7. Trying to convert: 2018-05-23T23:18:31.000Z into 2018-05-23 23:18:31 DateUtils class: public class DateUtils { public static String convertToNewFormat(String dateStr) throws ParseException { TimeZone utc = TimeZone.getTimeZone("UTC"); SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); sdf.setTimeZone(utc); Date convertedDate = sdf.parse(dateStr); return convertedDate.toString(); } } When trying to use it: String convertedDate = DateUtils.convertToNewFormat(

How to convert UTC Date String and remove the T and Z in Java?

匆匆过客 提交于 2020-06-11 06:08:09
问题 Am using Java 1.7. Trying to convert: 2018-05-23T23:18:31.000Z into 2018-05-23 23:18:31 DateUtils class: public class DateUtils { public static String convertToNewFormat(String dateStr) throws ParseException { TimeZone utc = TimeZone.getTimeZone("UTC"); SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); sdf.setTimeZone(utc); Date convertedDate = sdf.parse(dateStr); return convertedDate.toString(); } } When trying to use it: String convertedDate = DateUtils.convertToNewFormat(

DateTimeFormatter weekday seems off by one

こ雲淡風輕ζ 提交于 2020-06-10 02:35:08
问题 I'm porting an existing application from Joda-Time to Java 8 java.time . I ran into a problem where parsing a date/time string that contains a 'day of week' value triggered an exception in my unit tests. When parsing: 2016-12-21 20:50:25 Wednesday December +0000 3 using format: yyyy'-'MM'-'dd' 'HH':'mm':'ss' 'EEEE' 'MMMM' 'ZZ' 'e I get: java.time.format.DateTimeParseException: Text '2016-12-21 20:50:25 Wednesday December +0000 3' could not be parsed: Conflict found: Field DayOfWeek 3 differs

DateTimeParseException at index 0 with ThreeTenABP

大兔子大兔子 提交于 2020-05-16 03:25:11
问题 I'm trying to parse a time string with ThreeTenABP (because I have to support min SDK 19). I think the string is ISO 8601: 20200117T172638.000Z I get the following exception: org.threeten.bp.format.DateTimeParseException: Text '20200117T172638.000Z' could not be parsed at index 0 My code: Instant instant = Instant.parse("20200117T172638.000Z"); long time = instant.getEpochSecond(); Any help appreciated. Thanks in advance. 回答1: This is a little bit tricky alright. DateTimeFormatter

How to parse time in any format with LocalTime.parse?

时光毁灭记忆、已成空白 提交于 2020-05-15 10:09:13
问题 I am having trouble using java's LocalTime to parse a string with hours, minutes, and seconds. LocalTime t = LocalTime.parse("8:30:17"); // Simplification This throws the following exception: Exception in thread "main" java.time.format.DateTimeParseException: Text '8:30:17' could not be parsed at index 0 回答1: You'll need to pass in a custom DateTimeFormatter like this: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H:mm:ss"); LocalTime t = LocalTime.parse(times.get(i), formatter);

How to parse time in any format with LocalTime.parse?

谁都会走 提交于 2020-05-15 10:06:06
问题 I am having trouble using java's LocalTime to parse a string with hours, minutes, and seconds. LocalTime t = LocalTime.parse("8:30:17"); // Simplification This throws the following exception: Exception in thread "main" java.time.format.DateTimeParseException: Text '8:30:17' could not be parsed at index 0 回答1: You'll need to pass in a custom DateTimeFormatter like this: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H:mm:ss"); LocalTime t = LocalTime.parse(times.get(i), formatter);

milliseconds format to parse a datetime?

蓝咒 提交于 2020-05-09 17:14:51
问题 I need to parse a datetime contains milliseconds for matching the max value in a field containing this datetimes. For example: #standardSQL SELECT PARSE_DATETIME('%Y-%m-%d %H:%M:%S.%u','2017-08-18 16:04:40.890') Any suggestions? Thanks in advance. UPDATE : Convert to milliseconds, suddendly MAX() . #standardSQL WITH Input AS ( SELECT date FROM UNNEST([ DATETIME '2017-08-18 16:04:40.890', DATETIME '2017-07-27 11:09:10.347', DATETIME '2017-08-22 13:17:34.727', DATETIME '2017-08-22 13:17:34.737'

ZonedDateTime ignores 00 for ss part

杀马特。学长 韩版系。学妹 提交于 2020-01-30 12:23:51
问题 I am trying to convert string value "2018-10-11T12:00:00Z"; to ZonedDateTime. If I use the default ZonedDateTime.parse(zonedDateTime) then ss portion i.e. 00 is removed and I get "2018-10-11T12:00Z" as output. Can you please help how to retain 00 as SS part. String zonedDateTime = "2018-10-11T12:00:00Z"; ZonedDateTime z = ZonedDateTime.parse(zonedDateTime); System.out.println(z); // return 2018-10-11T12:00Z ZonedDateTime z1 = ZonedDateTime.parse (zonedDateTime, DateTimeFormatter.ofPattern(

How to Convert JSON Date Format to Simple Date Format? [duplicate]

Deadly 提交于 2020-01-17 18:02:44
问题 This question already has answers here : how to convert incoming Json date into java date format? (2 answers) Closed 2 years ago . I am receiving response of Date in JSON format like /Date(1521866513877+0530)/ which I want in format like this 24/03/2018 10:11:53 . 回答1: If there's no native way to parse that, try this regex pattern: \/Date\((\d+)\+(\d+)\)\/ I'm not a java guy but regex is everywhere. I looks like the date is in miliseconds so you need to divide 1521866513877 / 1000 to get the