I have a timestamp with a literal separating the date and time. It also includes the zero hour offset. Why am I unable to parse it to MMddHHmmss?
def srcFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'")
def srcFileTS = LocalDateTime.now().format(srcFormatter)
def tgtTSFormat = "MMddHHmmss"
def tgtFormatter = DateTimeFormatter.ofPattern(tgtTSFormat)
def tgtFileTS = LocalDateTime.parse(srcFileTS, tgtFormatter)
Caught: java.time.format.DateTimeParseException: Text ‘20240906T123119Z’ could not be parsed at index 8
java.time.format.DateTimeParseException: Text ‘20240906T123119Z’ could not be parsed at index 8
at switch.run(switch.groovy:14)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Figured out my issue
import java.util.regex.*
import java.time.format.DateTimeFormatter
import java.time.*
def tgtTSFormat = “MMddHHmmss”
def tgtFormatter = DateTimeFormatter.ofPattern(tgtTSFormat)
def srcFormatter = DateTimeFormatter.ofPattern(“yyyyMMdd’T’HHmmss’Z'”)
def srcFileTS = LocalDateTime.now().format(srcFormatter)
LocalDateTime srcDateTime = LocalDateTime.parse(srcFileTS, srcFormatter);
println(srcFileTS)
def tgtFileTS = srcDateTime.format(tgtFormatter)
println(tgtFileTS)