Converting normal time to metric

Hi everyone.

I’ve started the “journey” as a complete novice (I’ve done web design but not app development on my own). Love the learning format and process and looking forward to the next steps. I have a very specific problem I need to solve to show time in swift by converting time (hours, minutes, seconds) to metric.

The basic premise is that everything converts to base 10 system (Day has 10 metric Hours, Metric Hour has 100 metric minutes, One metric minute has 100 metric seconds etc). So as an example 12 noon in normal 24hour time is translated to 5.00 in the metric system.

1 metric second = 0.864 “normal” seconds.
1 metric minute = 1.44 “normal” minutes and
1 metric hours = 2.4 “normal” hour.

I’ve seen this working on javascript but I’d love to include it in swift and use it in an app.

Thanks in advance

I would make a custom type (like a struct or class) an inside there create a function that does the conversion for you.

To actually go about doing it, it’ll depend on the format of the input is. Is it a Date or a string that needs to be converted to a date? Etc

I’d suggest turning the input into minutes or hours and from there doing the conversion to metric

Thanks Mikaela.
I’ll start looking into this while learning more :slight_smile:
I see it in a scenario where I have the live time as a label perhaps and also have a button that toggles between normal and metric time.

1 Like

Okay! But your time still has to be in some kinda format like “12:20am”

You’d have it as a string from the label, but then convert it to a normal date, and then from there you can put it into metric time

1 Like