julia - 我想格式化日期,我们现在只有 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
推荐阅读
- angular - 使用服务在组件之间共享数据时组件未获取更新的数据
- key - GPG:查找密钥到期日期
- c#-7.0 - C# Expression Bodied Constructor - 有没有办法结合空检查?
- html - HTML5 验证:更改输入后重新验证字段
- kml - KML 图层排序
- groovy - 如何使用 spoc 在 Groovy 测试中测试嵌套列表对象的属性
- vbscript - 如何将文件夹中的所有 Excel 文件保存为管道分隔文件
- mysql - 将 MySQL 与下载的示例数据库连接
- linux-kernel - 为什么 i2c_device_id 是单独定义的,而不是 i2c_client 的一部分
- docker - 用葡萄牙语训练助手,Rasa NLU 不与 Docker 一起运行