method Date.parse
Parses ISO 8601 (.Iso8601, the default) or a pattern: Date.parse(s, "dd.MM.yyyy").
Example:
use std.time { Date }
fn main() io {
print("{Date.parse("03.11.2026", "dd.MM.yyyy")!.toIso()}")
match Date.parse("2026-13-40") {
Date d => print(d.toIso())
ParseError _ => print("invalid")
}
}Вывод
2026-11-03 invalid
pub(api) static fn parse(text: str, format: TimeFormat | str = .Iso8601) -> Date | ParseErrorС версии. 1.0.0-beta
Параметры
| Имя | Тип |
|---|---|
text | str |
format | TimeFormat | str = .Iso8601 |
Возвращает
Ошибки
ParseError@error- `ParseError` when the text does not match the format.
Эффекты
не объявлены (чистая, пока тело не говорит иное)
Определено в: std/time/time.oxl:1573