Reputation: 105
I am trying to convert milliseconds to minutes but unable to do so. I have been expecting the result in the form of MM:SS I have saved my results in a dataframe which shows the data type as milliseconds and even when I divide the entire row by 60000, the data type still remains to be milliseconds
delivery_time = delivery_timestamp - init_timestamp
783358-element Array{Millisecond,1}:
34200000 milliseconds
14580000 milliseconds
27300000 milliseconds
9180000 milliseconds
13560000 milliseconds
6960000 milliseconds
12600000 milliseconds
9600000 milliseconds
7500000 milliseconds
13080000 milliseconds
9180000 milliseconds
9600000 milliseconds
27660000 milliseconds
⋮
delivery_time = (delivery_time)/60000
783358-element Array{Millisecond,1}:
570 milliseconds
243 milliseconds
455 milliseconds
153 milliseconds
226 milliseconds
116 milliseconds
210 milliseconds
160 milliseconds
125 milliseconds
218 milliseconds
153 milliseconds
I am expecting the results to be
df.delivery_time
06:22
07:32
09:51
.
.
.
or even if I can get results as
df.delivery_time
570 minute
243 minute
455 minute
.
.
.
Upvotes: 1
Views: 590
Reputation: 105
thank you so much for help. You solved most of my problem. I am quite naive yet in Julia started a week back.
I had actually used -
df.delivery_time = map((x) -> convert(Time,x),df[:15])
with this as the result
783358-element Array{Time,1}:
09:30:00
04:03:00
07:35:00
02:33:00
03:46:00
01:56:00
Upvotes: 0
Reputation: 69949
You can convert Millisecond
to eg. Minute
only with loss of precision. Here is an example that does rounding to the nearest minute:
@. Minute(round(Int, Dates.value(delivery_time) / (1000 * 60)))
If you do not need Minute
values but simply floats without rounding you can do:
@. Dates.value(delivery_time) / (1000 * 60)
or e.g.
Dates.value.(delivery_time) / (1000 * 60)
if you prefer not to use @.
.
Finally you can write
Time(0) .+ delivery_time
which is lossless, but now the returned object is not a subtype of Period
and it will "wrap around" 24 hours. If you want to avoid wrapping use DateTime
instead of Time
above.
Upvotes: 1