# \[ANN\] TimeFloats.jl: Converting time to floats and vice versa

**URL:** <https://discourse.julialang.org/t/ann-timefloats-jl-converting-time-to-floats-and-vice-versa/136034>\
**Category:** Package Announcements\
**Tags:** dates\
**Created:** [March 5, 2026, 12:22pm UTC](https://discourse.julialang.org/t/ann-timefloats-jl-converting-time-to-floats-and-vice-versa/136034 "2026-03-05T12:22:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [March 5, 2026, 12:22pm UTC](https://discourse.julialang.org/t/ann-timefloats-jl-converting-time-to-floats-and-vice-versa/136034/1 "2026-03-05T12:22:08Z")

</div>

Hi all!

[`TimeFloats.jl`](https://github.com/yakir12/TimeFloats.jl) is a tiny utility package that converts between Julia’s `Dates` period types (`Nanosecond`, `Second`, `Hour`, `Time`, `CompoundPeriod`, etc.) and plain floating-point numbers, using any `FixedPeriod` as the unit of measurement.

My main motivation for creating this package was the fact that I’ve been copy-pasting `tosecond{T}(t::T) = t / convert(T, Base.Dates.Second(1))` from Kristoffer Carlsson’s [post](https://discourse.julialang.org/t/convert-time-interval-to-seconds/3806/2) for long enough..!

## Who needs this?

- Do you need to convert a `Dates.Time` to float seconds?

```julia
julia> tosecond(Time(13,39,42,652))
49182.652

```

- Do you need to convert a `Dates.CompoundPeriod` to float minutes?

```julia
julia> tofloat(Minute, Week(21) + Hour(32) + Millisecond(45))
213600.00075

```

- Do you need to convert a `Dates.Hour` to float nanoseconds?

```julia
julia> tofloat(Nanosecond, Hour(3))
1.08e13

```

- Or how about converting from a float seconds to its canonical form?

```julia
julia> fromsecond(92384756.9823465)
92384756 seconds, 982 milliseconds, 346 microseconds, 504 nanoseconds

```

- Or converting from a float milliseconds to `Minute`s (OBS: this approximates the result to the closest integer of minutes)?

```julia
julia> fromfloat(60_123, Millisecond)
60123 milliseconds

```

## Registration

~~Package registration will occur in 3 days.~~ After helpful [discussion](https://github.com/JuliaRegistries/General/pull/149846) with @aplavin I discovered DateFormats.jl which does basically the same as TimeFloats. There is a more detailed comparison between the two packages in TimeFloats’s README, but the similarity was enough to dissuade me from adding this to General. I’ll keep tinkering and see where this settles though.
