Creates a DateTime instance from a specific format.
(
string: str,
fmt: str,
tz: str | Timezone = UTC,
locale: str | None = None,
)
| 268 | |
| 269 | |
| 270 | def from_format( |
| 271 | string: str, |
| 272 | fmt: str, |
| 273 | tz: str | Timezone = UTC, |
| 274 | locale: str | None = None, |
| 275 | ) -> DateTime: |
| 276 | """ |
| 277 | Creates a DateTime instance from a specific format. |
| 278 | """ |
| 279 | parts = _formatter.parse(string, fmt, now(tz=tz), locale=locale) |
| 280 | if parts["tz"] is None: |
| 281 | parts["tz"] = tz |
| 282 | |
| 283 | return datetime(**parts) |
| 284 | |
| 285 | |
| 286 | def from_timestamp(timestamp: int | float, tz: str | Timezone = UTC) -> DateTime: |