如何解决我想格式化日期,我们现在只有yyyyq,我想获取YYYY-MM-DD
这是我的代码:
Dates.Year(div(19973,10)) # 1997 years
Dates.Month(round(mod(19973,10)*3)) # 9 months
上面的方法还可以,但是...
Dates.lastdayofquarter(Date(Dates.Year(div(19973,10)),Dates.Month(round(mod(19973,10)*3)),1))
# MethodError: no method matching Int64(::Year)
Closest candidates are:
Int64(!Matched::Union{Bool,Int32,Int64,UInt32,UInt64,UInt8,Int128,#Int16,Int8,UInt128,UInt16}) at boot.jl:708,Int64(!Matched::Ptr) at boot.jl:718,Int64(!Matched::Float32) at float.jl:706,...
Date(::Year,::Month,::Int64) at types.jl:368,top-level scope at untitled-b0de772dbeef3476c50547132427f175:73
include_string(::Function,::Module,::String,::String) at loading.jl:1088
解决方法
这里是:
julia> lastdayofquarter(Date(19973 ÷ 10,(19973 % 10)*3))
1997-09-30
请注意,÷
是整数除法,%
是模运算符,并且可以通过传递年份和月份来构造Date
对象。
或受到@phipsgabler评论启发的另一种方式:
julia> lastdayofquarter(Date(divrem(19973,10).*(1,3)...))
1997-09-30
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。