datetime-format

How to prevent auto-generated 'T' letter when parsing String to LocalDateTime using DateTimeFormatterBuilder [duplicate]

偶尔善良 提交于 2020-06-29 04:23:28
问题 This question already has answers here : Can’t rid of 'T' in LocalDateTime (3 answers) Closed 4 months ago . I have this fragment of code to bidirectional parsing String to LocalDateTime: public class ConvertLocalDateToString { private static final DateTimeFormatter CUSTOM_LOCAL_DATE; static { CUSTOM_LOCAL_DATE = new DateTimeFormatterBuilder() .appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD) .appendLiteral('-') .appendValue(MONTH_OF_YEAR, 2) .appendLiteral('-') .appendValue(DAY_OF_MONTH, 2)

How to prevent auto-generated 'T' letter when parsing String to LocalDateTime using DateTimeFormatterBuilder [duplicate]

随声附和 提交于 2020-06-29 04:23:08
问题 This question already has answers here : Can’t rid of 'T' in LocalDateTime (3 answers) Closed 4 months ago . I have this fragment of code to bidirectional parsing String to LocalDateTime: public class ConvertLocalDateToString { private static final DateTimeFormatter CUSTOM_LOCAL_DATE; static { CUSTOM_LOCAL_DATE = new DateTimeFormatterBuilder() .appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD) .appendLiteral('-') .appendValue(MONTH_OF_YEAR, 2) .appendLiteral('-') .appendValue(DAY_OF_MONTH, 2)

is there master date time pattern which will work for every similar date time patterns

故事扮演 提交于 2020-06-28 06:05:49
问题 My consumer received time format is String with value 20/5/14_9:22:25 or 20/5/14_9:22:5 or 20/5/14_12:22:25 or 20/10/14_9:2:25 etc... all the above have very diffrent date time pattern from yy/MM/dd_HH:mm:ss and there can be many posiblity's of having single digit day,month,hour,minute and/or seconds. is there a masterpattern which will i can use for DateTimeFormatter.ofPattern(format) which will work for all the above pattern?? 回答1: The patterns look the same DateTimeFormatter formatter =

is there master date time pattern which will work for every similar date time patterns

廉价感情. 提交于 2020-06-28 06:04:11
问题 My consumer received time format is String with value 20/5/14_9:22:25 or 20/5/14_9:22:5 or 20/5/14_12:22:25 or 20/10/14_9:2:25 etc... all the above have very diffrent date time pattern from yy/MM/dd_HH:mm:ss and there can be many posiblity's of having single digit day,month,hour,minute and/or seconds. is there a masterpattern which will i can use for DateTimeFormatter.ofPattern(format) which will work for all the above pattern?? 回答1: The patterns look the same DateTimeFormatter formatter =

Scala string to date conversion

半腔热情 提交于 2020-06-26 14:41:47
问题 I have a string format of a date but which is from a csv file: 20200520T0200 , assuming its in the format of (yyyyMMdd/T/24-hour format). I have managed to read the lines in the csv file and seperated it into an arraybuffer. My question is i cannot format the string into a date, as i need to use the date to calculate some values. As i will use this formatter to format all the values of the first element of my arraybuffer which is the time with strings of "20200406T0300, etc, etc, etc".

Scala string to date conversion

淺唱寂寞╮ 提交于 2020-06-26 14:41:34
问题 I have a string format of a date but which is from a csv file: 20200520T0200 , assuming its in the format of (yyyyMMdd/T/24-hour format). I have managed to read the lines in the csv file and seperated it into an arraybuffer. My question is i cannot format the string into a date, as i need to use the date to calculate some values. As i will use this formatter to format all the values of the first element of my arraybuffer which is the time with strings of "20200406T0300, etc, etc, etc".

Scala string to date conversion

落花浮王杯 提交于 2020-06-26 14:41:22
问题 I have a string format of a date but which is from a csv file: 20200520T0200 , assuming its in the format of (yyyyMMdd/T/24-hour format). I have managed to read the lines in the csv file and seperated it into an arraybuffer. My question is i cannot format the string into a date, as i need to use the date to calculate some values. As i will use this formatter to format all the values of the first element of my arraybuffer which is the time with strings of "20200406T0300, etc, etc, etc".

Is there a way to parse two different dateTime formats into LocalDateTime or Instant in java?

99封情书 提交于 2020-06-17 13:08:27
问题 How can we validate two formats "yyyy-MM-dd" and "yyyy-MM-dd'T'HH:mm:SSX" for a given string which can be of any of the two formats and either convert it to Instant or LocalDateTime? LocalDateTime dateTime; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd[\'T\'HH:mm:SSX]"); TemporalAccessor temporalAccessor = formatter.parseBest(now, LocalDateTime::from, LocalDate::from); if (temporalAccessor instanceof LocalDateTime) { dateTime = (LocalDateTime)temporalAccessor; } else {

Is there a way to parse two different dateTime formats into LocalDateTime or Instant in java?

牧云@^-^@ 提交于 2020-06-17 13:07:49
问题 How can we validate two formats "yyyy-MM-dd" and "yyyy-MM-dd'T'HH:mm:SSX" for a given string which can be of any of the two formats and either convert it to Instant or LocalDateTime? LocalDateTime dateTime; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd[\'T\'HH:mm:SSX]"); TemporalAccessor temporalAccessor = formatter.parseBest(now, LocalDateTime::from, LocalDate::from); if (temporalAccessor instanceof LocalDateTime) { dateTime = (LocalDateTime)temporalAccessor; } else {

How to convert LocalDateTime object into ISO string including time zone?

本秂侑毒 提交于 2020-06-12 02:49:22
问题 I am trying to convert a date/time string back and forth into a LocalDateTime object. I am using ThreeTenBp as the date/time library. String -> LocalDateTime val actual = LocalDateTime.parse("2016-12-27T08:15:05.674+01:00", DateTimeFormatter.ISO_DATE_TIME) val expected = LocalDateTime.of(2016, 12, 27, 8, 15, 5, 674000000) assertThat(actual).isEqualTo(expected) // Successful LocalDateTime -> String val dateTime = LocalDateTime.of(2016, 12, 27, 8, 15, 5, 674000000) val actual = dateTime.format