Hello,
I'm trying to parse Unix time to HH:MM:ss format. That's how my code looks like:
import times
let datetime = fromUnix(1623524119)
echo datetime
let time = parse($datetime, "yyyy-mm-dd HH:MM:ss")
echo time.format("HH:MM:ss")
Here's converted timestamp: 2021-06-12T20:55:19+02:00. When I run the code, this error occurs:
Error: unhandled exception: Failed to parse '2021-06-12T20:55:19+02:00' with format 'yyyy-mm-dd HH:MM:ss'. Unexpected character: T [TimeParseError]
As you can see, there's unexpected T character, and I'm not quite sure how to deal with this problem. Is there anyone who can help me? Thanks
Wait, why are you doing it in such a hacky way with parsing the stringified date? This works just fine:
import std/times
let datetime = fromUnix(1623524119)
echo datetime.format("HH:mm:ss")
And yes MM is for months, mm is for minutes.https://github.com/treeform/chrono - my timestamp, calendar and timezone lib has no problems with this:
import chrono
let ts = Timestamp(1623524119)
echo ts.formatIso()
let time = parseIsoTs(ts.formatIso())
echo time.format("{hour/2}:{minute/2}:{second/2}")
Also the mm/MM bug would not happen.