#C14308. Datetime Parsing Challenge

    ID: 43943 Type: Default 1000ms 256MiB

Datetime Parsing Challenge

Datetime Parsing Challenge

You are given a string representing a date and time. Your task is to parse this string into a valid datetime and output it in the standardized format (YYYY\text{-}MM\text{-}DD\ HH:MM:SS). The input string may follow one of several formats:

  • \(YYYY\text{-}MM\text{-}DD\ HH:MM:SS\)
  • \(YYYY/MM/DD\ HH:MM:SS\)
  • \(DD\text{-}MM\text{-}YYYY\ HH:MM:SS\)
  • \(DD/MM/YYYY\ HH:MM:SS\)
  • \(YYYY\text{-}MM\text{-}DDT\ HH:MM:SS\)

If the string does not match any of these formats or represents an invalid date (for example, an invalid month), your program should output an error message in the following format:

Date string 'input' is not in a valid format

Your solution must read the input from standard input (stdin) and write the result to standard output (stdout).

inputFormat

Input will consist of a single line containing the date/time string.

outputFormat

Output the parsed date and time in the format (YYYY\text{-}MM\text{-}DD\ HH:MM:SS) if the input is valid. Otherwise, output an error message exactly as specified.## sample

2023-10-05 14:30:00
2023-10-05 14:30:00