0

I have two string values in one key for the date

Case 1 : date can be a string value ="2010-10-15T09:27:37Z"

Case 2 : and sometimes it can be a "20130526160000"

but I have only one function to parse these two value into date object

how can i identify that current value for date is case 1 or case 2 so that i can parse and will not get error

xingbin
  • 27,410
  • 9
  • 53
  • 103
Mahi
  • 1,754
  • 2
  • 16
  • 37
  • 1
    Possible duplicate of [Parsing an ISO 8601 date in Java8 when all fields (including separators, but not including years) are optional](https://stackoverflow.com/questions/52815456/parsing-an-iso-8601-date-in-java8-when-all-fields-including-separators-but-not). There are a number of similar questions, please search. – Ole V.V. Jan 14 '19 at 07:46
  • A potential issue is the first format includes offset (`Z`) and the second one doesn’t. Do you know in which time zone or offset to interpret the latter? More generally, what is the expected result in each case? – Ole V.V. Jan 14 '19 at 07:48

1 Answers1

1

If there are only these two cases, you can check whether the string contains literal T or Z.

xingbin
  • 27,410
  • 9
  • 53
  • 103