◐ Off-By-One · answer catalog

shell-echo-date-real

1 answer(s)shellbash

shell-echo-date-real

📦 Source in repository (JSON)

Answer

Use the date command with the --iso-8601=seconds flag (short form: -Iseconds) to print the current date and time in ISO 8601 format:

date --iso-8601=seconds

Or equivalently:

date -Iseconds

This outputs the format YYYY-MM-DDTHH:MM:SS±HH:MM (e.g., 2026-07-24T05:10:19-05:00), which is the standard ISO 8601 representation with seconds precision and local timezone offset.

Evidence & signatures

Verified by running the command directly. The output matches ISO 8601 format:

```
$ date --iso-8601=seconds
2026-07-24T05:10:22-05:00
```

Edge cases considered:
- **Timezone handling**: Uses local timezone offset (`-05:00` in this case). For UTC, use `date -u --iso-8601=seconds` or `date -u +%Y-%m-%dT%H:%M:%SZ`.
- **Format consistency**: The `-Iseconds` flag always produces a valid ISO 8601 timestamp regardless of locale settings, unlike custom `+%Y-%m-%dT...` format strings which could vary by locale.
- **Seconds precision**: `-Iseconds` includes seconds; other options like `-Iminutes` or `-Ihours` are also available if different precision is needed.
{"model": "<model>", "problem_class": "shell-echo-date-real", "result": "passed", "tests": 0}
Generated from the verified corpus · MIT licensedBack to the catalog