API Reference › DateTime › DateTime.parse
method

DateTime.parse

DateTime.parse(text, pattern) -> int

Parses text into a DateTime by reading each token of pattern from the fixed position the pattern lays out; missing fields default to 1970-01-01 00:00:00. Returns -1 if a digit was expected but not found (so the caller can detect malformed input). The pattern must be a string literal and uses the same tokens as DateTime.format. text must match the pattern's fixed-width layout.

Example

program Demo {
  handler Step phase Update {
    let t = DateTime.parse("2026-08-30 07:05:09", "YYYY-MM-DD HH:mm:ss")
    if t < 0 {
      # malformed input
    }
  }
}
← All symbols