简体   繁体   English

Julia / Dates:将时间跨度从“天”转换为“年”或“ Float64”

[英]Julia/Dates : convert a timespan from “days” to “year” or “Float64”

I would like to convert a timespan from "days" to "year" or "Float64" 我想将时间跨度从“天”转换为“年”或“ Float64”

let be at timespan t : 设在时间跨度t

t = Date("2000-02-04") - Date("1996-06-04")

However each following lines give me an error 但是以下每一行给我一个错误

t/365
Float64(t)
parse(Float64,t)
convert(Dates.Year, t)

You can get the value stored in t and divide it by 365 您可以获取存储在t的值并将其除以365

julia> Dates.value(t)/365
3.671232876712329

Note however that this assumes that each year is 365 days which is not true. 但是请注意,这是假设每年为365天,这是不正确的。 For some scenarios a more elegant solution would be to count the years assuming that the date starts at some point, have a look at the example below: 对于某些情况,一个更优雅的解决方案是假设日期从某个时间点开始计算年份,请看下面的示例:

julia> d0 = Date("2000-01-01")
2000-01-01

julia> d1 = d0 + t
2003-09-02

julia> year(d1)-year(d0), month(d1)-month(d0), day(d1) - day(d0)
(3, 8, 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM